把这些配置文件的基础框架整理在此,以方便自己随时搜索复制。包括:Spring配置文件applicationContext.xml;Spring和Mybatis整合时的mybatis配置文件mybatis-config.xml;Spring与Mybatis整合的配置文件spring-mybatis.xml ;db.properties数据库账号密码配置文件;Spring-MVC配置文件spring-mvc.xml;pring整合service层的配置文件spring-service.xml;SSH项目开发web.xml配置文件。详细如下:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
1.Spring配置文件applicationContext.xml的基础框架:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!--开启自动注解--> <context:annotation-config/> <!--AOP支持--> <!--<aop:aspectj-autoproxy />--> </beans>本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
2.Spring和Mybatis整合时的mybatis配置文件mybatis-config.xml基础框架:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!--日志开启--> <setting name="logImpl" value="STDOUT_LOGGING"/> <!--开启MYSQL的下划线与Class类中驼峰属性的自动映射--> <setting name="mapUnderscoreToCamelCase" value="true"/> </settings> <!--自动别名--> <typeAliases> <package name="***.pojo"/> </typeAliases> <!--mappers加载--> <mappers> <mapper class="***" /> </mappers> </configuration>本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
3.Spring与Mybatis整合的配置文件spring-mybatis.xml 基础框架本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
这里使用的是c3p0连接池,同时数据库账号文件写在db.properties文件中,注意c3po配置数据源时数据库账号属性是user而不是username。可能和平常自己的习惯不一样。还有driverClass、jdbcUrl属性。本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!--数据库配置文件加载--> <context:property-placeholder location="classpath:db.properties"/> <!--数据库连接池--> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}"/> <property name="maxPoolSize" value="10" /> <property name="minPoolSize" value="5" /> <property name="checkoutTimeout" value="5000" /> <property name="acquireRetryAttempts" value="2" /> </bean> <!--SqlSessionFactory配置--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis-config.xml" /> </bean> <!--dao接口--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> <property name="basePackage" value="****.dao" /> </bean> </beans>本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
4.db.properties数据库账号密码配置文件基础框架如下:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/test?useSSL=true&useUnicode=true&characterEncoding=UTF-8 jdbc.username=user jdbc.password=111111本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
5.Spring-MVC配置文件spring-mvc.xml基础框架如下:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!--注解驱动--> <mvc:annotation-driven/> <mvc:default-servlet-handler /> <!--扫描包--> <context:component-scan base-package="***.controllers" /> <!--加载视图--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans>本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
6.Spring整合service层的配置文件spring-service.xml基础框架如下:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="****.services" /> <!--声明式事务提交--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans>本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
7. SSH项目开发web.xml配置文件基础框架如下:本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--乱码过滤--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>Encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>本文地址:http://www.04007.cn/article/903.html,未经许可,不得转载.
本文地址:http://www.04007.cn/article/903.html 未经许可,不得转载. 手机访问本页请扫描右下方二维码.
![]() |
![]() |
手机扫码直接打开本页面 |