SSM整合配置文件

Maven构建。直接上代码。
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<groupId>cn.anycode.ssmgroupId>
	<artifactId>ssmartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<packaging>warpackaging>

	<properties>
		<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>

		
		<jdk.version>1.8jdk.version>
		<tomcat.version>2.2tomcat.version>
		<webserver.port>8181webserver.port>
	properties>

	
	<repositories>
		<repository>
			<id>jeesite-reposid>
			<name>Jeesite Repositoryname>
			<url>http://maven.aliyun.com/nexus/content/groups/publicurl>
		repository>
	repositories>

	
	<pluginRepositories>
		<pluginRepository>
			<id>jeesite-reposid>
			<name>Jeesite Repositoryname>
			<url>http://maven.aliyun.com/nexus/content/groups/publicurl>
		pluginRepository>
	pluginRepositories>

	<dependencies>
		<dependency>
			<groupId>junitgroupId>
			<artifactId>junitartifactId>
			<version>4.12version>
			<scope>testscope>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-contextartifactId>
			<version>5.0.6.RELEASEversion>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-webartifactId>
			<version>5.0.6.RELEASEversion>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-webmvcartifactId>
			<version>5.0.6.RELEASEversion>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-txartifactId>
			<version>5.0.6.RELEASEversion>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-aspectsartifactId>
			<version>5.0.6.RELEASEversion>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-ormartifactId>
			<version>5.0.6.RELEASEversion>
		dependency>
		<dependency>
			<groupId>javax.servletgroupId>
			<artifactId>javax.servlet-apiartifactId>
			<version>3.1.0version>
			<scope>providedscope>
		dependency>
		<dependency>
			<groupId>javax.servlet.jspgroupId>
			<artifactId>jsp-apiartifactId>
			<version>2.2version>
			<scope>providedscope>
		dependency>
		<dependency>
			<groupId>org.slf4jgroupId>
			<artifactId>slf4j-log4j12artifactId>
			<version>1.7.25version>
			<scope>testscope>
		dependency>
		<dependency>
			<groupId>commons-logginggroupId>
			<artifactId>commons-loggingartifactId>
			<version>1.2version>
		dependency>
		<dependency>
			<groupId>org.apache.taglibsgroupId>
			<artifactId>taglibs-standard-specartifactId>
			<version>1.2.5version>
			<type>bundletype>
		dependency>
		<dependency>
			<groupId>org.apache.taglibsgroupId>
			<artifactId>taglibs-standard-implartifactId>
			<version>1.2.5version>
			<type>bundletype>
		dependency>
		<dependency>
			<groupId>mysqlgroupId>
			<artifactId>mysql-connector-javaartifactId>
			<version>5.1.46version>
		dependency>
		<dependency>
			<groupId>com.oraclegroupId>
			<artifactId>ojdbc6artifactId>
			<version>12.1.0.1-atlassian-hostedversion>
		dependency>
		<dependency>
			<groupId>com.mchangegroupId>
			<artifactId>c3p0artifactId>
			<version>0.9.5.2version>
		dependency>
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatisartifactId>
			<version>3.4.6version>
		dependency>
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatis-springartifactId>
			<version>1.3.2version>
		dependency>
		<dependency>
			<groupId>org.mybatis.generatorgroupId>
			<artifactId>mybatis-generator-coreartifactId>
			<version>1.3.7version>
		dependency>
		<dependency>
			<groupId>org.mybatis.cachesgroupId>
			<artifactId>mybatis-ehcacheartifactId>
			<version>1.1.0version>
		dependency>
		<dependency>
			<groupId>com.github.pagehelpergroupId>
			<artifactId>pagehelperartifactId>
			<version>5.1.4version>
		dependency>
		<dependency>
			<groupId>com.alibabagroupId>
			<artifactId>druidartifactId>
			<version>1.0.18version>
		dependency>
		<dependency>
			<groupId>log4jgroupId>
			<artifactId>log4jartifactId>
			<version>1.2.17version>
			<type>bundletype>
		dependency>
	dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.felixgroupId>
				<artifactId>maven-bundle-pluginartifactId>
				<extensions>trueextensions>
			plugin>

			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-compiler-pluginartifactId>
				<version>3.5.1version>
				<configuration>
					<source>${jdk.version}source>
					<target>${jdk.version}target>
					<showWarnings>trueshowWarnings>
				configuration>
			plugin>
			
			
			<plugin>
				<groupId>org.apache.tomcat.mavengroupId>
				<artifactId>tomcat7-maven-pluginartifactId>
				<version>${tomcat.version}version> 
				<configuration>
					<port>${webserver.port}port>
					<path>/${project.artifactId}path>
					<uriEncoding>${project.build.sourceEncoding}uriEncoding>
				configuration>
			plugin>
		plugins>
	build>

project>

web.xml


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	id="WebApp_ID" version="3.1">
	
	
	<context-param>
		<param-name>contextConfigLocationparam-name>
		<param-value>classpath:spring.xmlparam-value>
	context-param>

	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
	listener>
	
	
	<servlet>
		<servlet-name>springDispatcherServletservlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
		<init-param>
			<param-name>contextConfigLocationparam-name>
			<param-value>classpath:springmvc.xmlparam-value>
		init-param>
		<load-on-startup>1load-on-startup>
	servlet>

	
	<servlet-mapping>
		<servlet-name>springDispatcherServletservlet-name>
		<url-pattern>/url-pattern>
	servlet-mapping>
	
	<filter>
		<filter-name>encodingFilterfilter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
		<init-param>
			<param-name>encodingparam-name>
			<param-value>UTF-8param-value>
		init-param>
		<init-param>
			<param-name>forceEncodingparam-name>
			<param-value>trueparam-value>
		init-param>
	filter>
	<filter-mapping>
		<filter-name>encodingFilterfilter-name>
		<url-pattern>/*url-pattern>
	filter-mapping>
web-app>

spring.xml


<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:util="http://www.springframework.org/schema/util"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
	xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
		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-4.3.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">

	<context:property-placeholder
		location="classpath:jdbc.properties" /> 
	
	
	<context:component-scan
		base-package="cn.anycode.ssm">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:exclude-filter type="annotation"
			expression="org.springframework.web.bind.annotation.ControllerAdvice" />
	context:component-scan>

	
	<bean id="dataSource"
		class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
		destroy-method="close">
		
		<property name="driverClassName" value="${jdbc.driver}" />

		
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		
		<property name="initialSize" value="${jdbc.pool.init}" />
		<property name="minIdle" value="${jdbc.pool.minIdle}" />
		<property name="maxActive" value="${jdbc.pool.maxActive}" />
		
		<property name="maxWait" value="60000" />
		
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		
		<property name="minEvictableIdleTimeMillis" value="300000" />
		<property name="validationQuery" value="${jdbc.testSql}" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		
		<property name="filters" value="stat" />
	bean>

	
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource">property>
	bean>
	
	
	<tx:advice id="txAdvice"
		transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="select*" read-only="true" />
			<tx:method name="*" read-only="false" />
		tx:attributes>
	tx:advice>
	
	
	<aop:config>
		<aop:pointcut
			expression="execution(* cn.anycode.ssm.*.service.*.*(..))"
			id="txPointcut" />
		<aop:advisor advice-ref="txAdvice"
			pointcut-ref="txPointcut" />
	aop:config>
	
	
	<bean id="sqlSessionFactory"
		class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource">property>
		<property name="typeAliasesPackage" value="cn.anycode.ssm"/>
        <property name="mapperLocations" value="classpath:/mappings/**/*.xml"/>
		<property name="configLocation" value="classpath:/mybatis-config.xml">property>
	bean>
	
	<mybatis-spring:scan
		base-package="cn.anycode.ssm.*.dao" />

beans>

springmvc.xml


<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"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		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-4.3.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">

	<context:component-scan
		base-package="cn.anycode.ssm" use-default-filters="false">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:include-filter type="annotation"
			expression="org.springframework.web.bind.annotation.ControllerAdvice" />
	context:component-scan>
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/">property>
		<property name="suffix" value=".jsp">property>
	bean>
	<mvc:annotation-driven />
	<mvc:default-servlet-handler/>

beans>

mybatis-config.xml



<configuration>

	
	<settings>
		
		<setting name="cacheEnabled" value="true"/>
		
		
		<setting name="lazyLoadingEnabled" value="true"/>
		
		
		<setting name="aggressiveLazyLoading" value="true"/>
		
		
		<setting name="multipleResultSetsEnabled" value="true"/>
		
		
		<setting name="useColumnLabel" value="true"/>
		
		
		<setting name="useGeneratedKeys" value="false"/>
		
		  
		<setting name="autoMappingBehavior" value="PARTIAL"/>
		
		
		<setting name="defaultExecutorType" value="SIMPLE"/>
		
		
		<setting name="mapUnderscoreToCamelCase" value="true"/>
		
		
        <setting name="localCacheScope" value="SESSION"/>
		
        
        <setting name="jdbcTypeForNull" value="NULL"/>
		
	settings>
	
configuration>

你可能感兴趣的:(SSM整合配置文件)