IT虾米网

ssm文件配置详解

luoye 2018年07月05日 编程语言 221 0
 1 <?xml version="1.0" encoding="UTF-8"?>   
 2     <beans xmlns="http://www.springframework.org/schema/beans"   
 3             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
 4             xmlns:aop="http://www.springframework.org/schema/aop"   
 5             xmlns:p="http://www.springframework.org/schema/p"   
 6             xmlns:tx="http://www.springframework.org/schema/tx"   
 7             xmlns:context="http://www.springframework.org/schema/context"   
 8             xsi:schemaLocation="    
 9                 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    
10                 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd    
11                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">   
12             
13         <!-- Properties文件读取配置,base的properties -->   
14         <context:property-placeholder location="classpath:jdbc.properties"/>   
15             
16         <!-- JNDI获取数据源(使用dbcp连接池) -->   
17         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton"> 
18             <property name="driverClassName" value="${driverClassName}"/> 
19             <property name="url" value="${url}"/> 
20             <property name="username" value="${uname}"/> 
21             <property name="password" value="${password}"/> 
22             <property name="initialSize" value="${initialSize}"/> 
23             <property name="maxActive" value="${maxActive}"/> 
24             <property name="maxIdle" value="${maxIdle}"/> 
25             <property name="minIdle" value="${minIdle}"/> 
26             <property name="maxWait" value="${maxWait}"/> 
27             <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/> 
28             <property name="removeAbandoned" value="${removeAbandoned}"/> 
29             <!-- sql 心跳 --> 
30             <property name= "testWhileIdle" value="true"/> 
31             <property name= "testOnBorrow" value="false"/> 
32             <property name= "testOnReturn" value="false"/> 
33             <property name= "validationQuery" value="select 1"/> 
34             <property name= "timeBetweenEvictionRunsMillis" value="60000"/> 
35             <property name= "numTestsPerEvictionRun" value="${maxActive}"/> 
36          </bean>  
37           
38         <!--redis 配置 开始--> 
39         <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> 
40             <property  name="maxActive"  value="90" />   
41             <property  name="maxIdle"   value="5" />   
42             <property  name="maxWait"  value="1000" />   
43             <property  name="testOnBorrow"  value="true" />  
44         </bean> 
45         <bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy" > 
46             <constructor-arg ref="jedisPoolConfig"/> 
47             <constructor-arg value="10.0.0.194"/> 
48             <constructor-arg value="6379"/> 
49         </bean> 
50         <bean id="redisAPI" class="org.slsale.common.RedisAPI"> 
51             <property name="jedisPool" ref="jedisPool"/> 
52         </bean> 
53         <!-- redis 配置结束 --> 
54  
55         <!-- mybatis-spring 配置 结束 --> 
56              
57              
58         <!-- enable autowire 启用spring mvc 注解-->   
59         <context:annotation-config />   
60         <!-- enable transaction demarcation with annotations -->   
61         <tx:annotation-driven />  
62             
63         <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->   
64         <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">   
65             <property name="dataSource" ref="dataSource" />   
66         </bean>   
67          <!-- define the SqlSessionFactory, notice that configLocation is not needed when you use MapperFactoryBean -->   
68         <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">   
69             <property name="dataSource" ref="dataSource" />   
70             <property name="configLocation" value="classpath:mybatis-config.xml" />   
71         </bean>  
72           
73         <!-- AOP 事务处理 开始 -->     
74         <aop:aspectj-autoproxy /> 
75         <aop:config  proxy-target-class="true">   
76             <aop:pointcut expression="execution(* *org.slsale.service..*(..))" id="transService"/> 
77             <aop:advisor pointcut-ref="transService" advice-ref="txAdvice" /> 
78         </aop:config>  
79         <tx:advice id="txAdvice" transaction-manager="transactionManager">   
80             <tx:attributes>   
81                <tx:method name="hl*"  propagation="REQUIRED" rollback-for="Exception"  /> 
82             </tx:attributes>   
83         </tx:advice>  
84         <!-- AOP 事务处理 结束 --> 
85                 
86           <!-- scan for mappers and let them be autowired -->   
87         <!-- Mapper接口所在包名,Spring会自动查找其下的Mapper --> 
88         <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">   
89             <property name="basePackage" value="org.slsale.dao" />   
90         </bean> 
91     </beans>  
 1 <?xml version="1.0" encoding="UTF-8"?>   
 2     <!DOCTYPE configuration    
 3         PUBLIC "-//mybatis.org//DTD Config 3.0//EN"    
 4         "http://mybatis.org/dtd/mybatis-3-config.dtd">   
 5     <configuration>   
 6         <settings>   
 7             <!-- changes from the defaults -->   
 8             <setting name="lazyLoadingEnabled" value="false" />   
 9         </settings>   
10        <typeAliases>   
11            <!--这里给实体类取别名,方便在mapper配置文件中使用-->  
12            <!-- add by bdqn_hl 2014-2-21 start --> 
13            <typeAlias alias="user" type="org.slsale.pojo.User"/>  
14            <typeAlias alias="function" type="org.slsale.pojo.Function"/>  
15            <typeAlias alias="authority" type="org.slsale.pojo.Authority"/>  
16            <typeAlias alias="dataDictionary" type="org.slsale.pojo.DataDictionary"/>  
17            <typeAlias alias="role" type="org.slsale.pojo.Role"/>  
18            <typeAlias alias="affiche" type="org.slsale.pojo.Affiche"/>  
19            <typeAlias alias="goodsInfo" type="org.slsale.pojo.GoodsInfo"/>  
20            <typeAlias alias="information" type="org.slsale.pojo.Information"/>  
21            <typeAlias alias="goodsPack" type="org.slsale.pojo.GoodsPack"/>  
22            <typeAlias alias="goodsPackAffiliated" type="org.slsale.pojo.GoodsPackAffiliated"/>  
23            <typeAlias alias="uploadTemp" type="org.slsale.pojo.UploadTemp"/> 
24            <typeAlias alias="leaveMessage" type="org.slsale.pojo.LeaveMessage"/> 
25            <typeAlias alias="reply" type="org.slsale.pojo.Reply"/> 
26            <!-- add by bdqn_hl 2014-2-21 end --> 
27             
28            <!-- add by bdqn_shy 2014-4-9 start --> 
29            <typeAlias alias="userAccountLog" type="org.slsale.pojo.UserAccountLog"/>  
30            <!-- add by bdqn_shy 2014-4-9 end --> 
31        </typeAliases>   
32    </configuration>  
mybatis-config.xml
 1 <?xml version="1.0" encoding="UTF-8"?> 
 2 <beans xmlns="http://www.springframework.org/schema/beans" 
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 4        xmlns:mvc="http://www.springframework.org/schema/mvc" 
 5        xmlns:context="http://www.springframework.org/schema/context" 
 6        xmlns:aop="http://www.springframework.org/schema/aop" 
 7        xmlns:tx="http://www.springframework.org/schema/tx" 
 8        xmlns:p="http://www.springframework.org/schema/p" 
 9        xsi:schemaLocation="http://www.springframework.org/schema/beans 
10            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
11            http://www.springframework.org/schema/context 
12            http://www.springframework.org/schema/context/spring-context-2.5.xsd 
13            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
14            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
15            http://www.springframework.org/schema/mvc 
16            http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 
17  
18     <mvc:resources mapping="/statics/**" location="/statics/" /> 
19     <mvc:annotation-driven/> 
20      
21     <!-- 完成请求和注解POJO的映射 --> 
22     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 
23     <!-- 装配controller --> 
24     <context:component-scan base-package="org.slsale" > 
25         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>   
26     </context:component-scan>  
27     <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 --> 
28     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"  
29         p:prefix="/WEB-INF/pages/" p:suffix=".jsp" /> 
30  
31     <!-- 支持上传文件 -->   
32     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> 
33      
34     <mvc:interceptors> 
35       <mvc:interceptor> 
36         <mvc:mapping path="/backend/**" /> 
37         <mvc:mapping path="/informanage/**" /> 
38         <mvc:mapping path="/member/**" /> 
39         <mvc:mapping path="/message/**" /> 
40         <bean class="org.slsale.interceptor.SysInterceptor"> 
41         </bean> 
42       </mvc:interceptor> 
43     </mvc:interceptors> 
44      
45      
46 </beans> 
spring-servlet.xml
 1 <?xml version="1.0" encoding="UTF-8"?> 
 2 <web-app version="3.0"  
 3     xmlns="http://java.sun.com/xml/ns/javaee"  
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
 6     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
 7   <display-name></display-name>     
 8    
 9   <!--指定spring bean的配置文件所在目录  --> 
10   <context-param> 
11       <param-name>contextConfigLocation</param-name> 
12       <param-value>classpath:applicationContext-*.xml</param-value> 
13   </context-param> 
14    
15   <!-- 配置spring的字符编码为utf-8 --> 
16   <filter> 
17       <filter-name>encodingFilter</filter-name> 
18       <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
19       <init-param> 
20       <param-name>encoding</param-name> 
21       <param-value>utf-8</param-value> 
22       </init-param> 
23       <init-param> 
24       <param-name>forceEncoding</param-name> 
25       <param-value>true</param-value> 
26       </init-param> 
27   </filter> 
28   <filter-mapping> 
29       <filter-name>encodingFilter</filter-name> 
30       <url-pattern>/*</url-pattern> 
31   </filter-mapping> 
32    
33   <!--springMVC的配置  --> 
34   <servlet> 
35       <servlet-name>springmvc</servlet-name> 
36       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
37       <init-param> 
38       <param-name>contextConfigLocation</param-name> 
39       <param-value>classpath:springmvc-servlet.xml</param-value> 
40       </init-param> 
41       <load-on-startup>1</load-on-startup> 
42   </servlet> 
43   <servlet-mapping> 
44       <servlet-name>springmvc</servlet-name> 
45       <url-pattern>/</url-pattern> 
46   </servlet-mapping> 
47    
48   <!-- spring配置 --> 
49   <listener> 
50      <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class> 
51   </listener> 
52    
53   <!-- log4j配置 --> 
54   <context-param> 
55       <param-name>log4jConfigLocation</param-name> 
56       <param-value>classpath:log4j.properties</param-value> 
57   </context-param> 
58   <context-param> 
59       <param-name>webAppRootKey</param-name> 
60       <param-value>SL.root</param-value> 
61   </context-param> 
62    
63   <!-- spring加载log4j的监听 --> 
64   <listener> 
65       <listener-class> org.springframework.web.util.Log4jConfigListener</listener-class> 
66   </listener> 
67    
68   <welcome-file-list> 
69     <welcome-file>/WEB-INF/pages/index.jsp</welcome-file> 
70   </welcome-file-list> 
71 </web-app>
web.xml

 

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

使用socket实现聊天功能详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。