SSM框架各配置文件模板
mybatis-config.xml配置文件
`
<typeAliases>
<package name="com.xing.pojo"/>
</typeAliases>
<!-- <mappers>-->
<!-- <mapper class="com.xing.dao.BookMapper"/>-->
<!-- </mappers>-->
`
db.properties配置文件
点击查看代码
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSl=false&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
jdbc.username=root
jdbc.password=123456
# 在dbcp中最大连接数已改名为maxActive
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
applicationContext.xml配置文件
点击查看代码
<?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: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/context
http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="springmvc-config.xml"/>
<!--扫描数据源db.properties-->
<context:property-placeholder location="classpath:db.properties"/>
<!-- <context:property-placeholder location="db.properties"/> 这种是会报错的,必须滴啊classpath-->
<!--配置c3p0数据源-->
<!-- <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">-->
<!-- <property name="jdbcUrl" value="${jdbc.url}"/>-->
<!-- </bean>-->
<bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="driverClass" value="${jdbc.driver}"/>
<property name="maxPoolSize" value="${jdbc.maxTotal}"/>
<property name="maxIdleTime" value="${jdbc.maxIdle}"/>
<property name="initialPoolSize" value="${jdbc.initialSize}"/>
</bean>
<!-- 配置SQLSessionFactory工厂-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<!--配置mapper扫描器, 同时也把BookMapper接口注入到bean中了,避免了将所有mapper接口一个一个的注入到bean中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xing.dao"/>
</bean>
<context:component-scan base-package="com.xing.service"/>
</beans>
SpringMVC配置文件
点击查看代码
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 静态资源过滤-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<context:component-scan base-package="com.xing.controller"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.xing.config.LoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
</beans>

浙公网安备 33010602011771号