zoukankan      html  css  js  c++  java
  • SSM框架配置文件

    1、Spring

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans:beans xmlns="http://www.springframework.org/schema/security"
     3     xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://www.springframework.org/schema/beans  
     5            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
     6            http://www.springframework.org/schema/security  
     7            http://www.springframework.org/schema/security/spring-security.xsd">
     8     <beans:import resource="spring-security.xml" />
     9     <beans:import resource="spring-mybatis.xml" />
    10 </beans:beans>  
    spring-config.xml

    2、SpringMVC

      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" xmlns:p="http://www.springframework.org/schema/p"
      4     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
      5     xmlns:util="http://www.springframework.org/schema/util"
      6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
      7              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      8              http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd              
      9              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
     10 
     11     <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
     12     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
     13         <property name="synchronizeOnSession" value="true" />
     14         <property name="customArgumentResolvers">
     15             <list>
     16                 <bean class="wyp.filterexpression.EntityResolver" />
     17             </list>
     18         </property>
     19     </bean>
     20     
     21     <!-- http://hecks.iteye.com/blog/2165606 Spring MVC 3.2中@ResponseBody返回乱码的完美解决方案 -->
     22     <mvc:annotation-driven>
     23         <mvc:message-converters>
     24             <!-- default StringHttpMessageConverter, solve encoding problem -->
     25             <bean class="org.springframework.http.converter.StringHttpMessageConverter">
     26                 <constructor-arg value="UTF-8" />
     27                 <property name="writeAcceptCharset" value="false" />
     28             </bean>
     29         </mvc:message-converters>
     30         <!-- http://shengwangi.blogspot.com/2015/09/asynchronous-spring-mvc-hello-world.html -->
     31         <mvc:async-support default-timeout="1200000" task-executor="taskExecutor"/>
     32     </mvc:annotation-driven>
     33     
     34     <!-- modify the parameters of thread pool -->
     35     <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
     36         <property name="corePoolSize" value="5"/>
     37         <property name="maxPoolSize" value="50"/>
     38         <property name="queueCapacity" value="10"/>
     39         <property name="keepAliveSeconds" value="1200"/>
     40       </bean>
     41 
     42     <mvc:default-servlet-handler default-servlet-name="default" />
     43     <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
     44     <mvc:resources mapping="/Scripts/**" location="/Scripts/" />
     45     <mvc:resources mapping="/Content/**" location="/Content/" />
     46     
     47     <!-- 配置velocity引擎 -->
     48     <bean id="velocityconfig"
     49         class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
     50         <!-- 模板存放的路徑 -->
     51         <property name="resourceLoaderPath" value="/" />
     52         <!-- Velocity配置文件 -->
     53         <property name="configLocation" value="classpath:velocity.properties" />
     54     </bean>
     55     <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
     56     <bean id="jspconfig" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     57         <property name="prefix">
     58             <value>/WEB-INF/jsp/</value>
     59         </property>
     60         <property name="suffix" value=".jsp" />
     61         <property name="order" value="2" />
     62     </bean>
     63     <!-- 配置Velocity视图的显示 -->
     64     <bean id="vmconfig" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
     65         <property name="prefix" value="/WEB-INF/vm/" />
     66         <property name="suffix" value=".vm" />
     67         <!-- 视图文件的后缀名 -->
     68         <!-- 视图文件的前綴,即存放的路徑 -->
     69         <property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml" />
     70         <!--toolbox配置文件路徑 -->
     71         <property name="dateToolAttribute" value="date" />
     72         <!--日期函數名稱 -->
     73         <property name="numberToolAttribute" value="number" />
     74         <!--數字函數名稱 -->
     75         <property name="contentType" value="text/html;charset=UTF-8" />
     76         <property name="exposeSpringMacroHelpers" value="true" />
     77         <!--是否使用spring對宏定義的支持 -->
     78         <property name="exposeRequestAttributes" value="true" />
     79         <!--是否開放request屬性 -->
     80         <property name="requestContextAttribute" value="rc" />
     81         <!--request屬性引用名稱 -->
     82         <property name="layoutUrl" value="/WEB-INF/vm/Shared/_Layout.vm" />
     83         <!--指定默認layout文件 -->
     84         <property name="order" value="1" />
     85     </bean>
     86     <!-- 视图解析器,根据视图的名称new ModelAndView(name),在配置文件查找对应的bean配置 -->
     87     <bean id="beanconfig" class="org.springframework.web.servlet.view.BeanNameViewResolver">
     88         <property name="order" value="0" />
     89     </bean>
     90     
     91     <!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->  
     92     <bean id="multipartResolver"    
     93         class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
     94         <!-- 默认编码 -->  
     95         <property name="defaultEncoding" value="utf-8" />    
     96         <!-- 文件大小最大值 -->  
     97         <property name="maxUploadSize" value="10485760000" />    
     98         <!-- 内存中的最大值 -->  
     99         <property name="maxInMemorySize" value="40960" />    
    100     </bean>
    101     
    102     <!-- 下面就是自定义异常处理的handler和view -->
    103     <bean id="exceptionHandler" class="wyp.ssm.demo.ExceptionResolver" />
    104     <bean id="exceptionView" class="wyp.ssm.demo.ExceptionView" />
    105     <!-- 扫描spring mvc 的 controller 所在的默认包名 -->
    106     <context:component-scan base-package="wyp.ssm.demo" />
    107 </beans>
    spring-mvc.xml

    3、SpringMybatis

     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:context="http://www.springframework.org/schema/context"
     5     xsi:schemaLocation="http://www.springframework.org/schema/beans    
     6                             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
     7                             http://www.springframework.org/schema/context    
     8                             http://www.springframework.org/schema/context/spring-context-3.1.xsd    
     9                             http://www.springframework.org/schema/mvc    
    10                             http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    11     <!-- 自动扫描 -->
    12     <context:component-scan base-package="wyp.ssm.demo.db" />
    13     <!-- 引入配置文件 -->
    14     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    15         <property name="location" value="classpath:jdbc.properties" />
    16     </bean>
    17     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    18         <property name="driverClassName" value="${driver}" />
    19         <property name="url" value="${url}" />
    20         <property name="username" value="${username}" />
    21         <property name="password" value="${password}" />
    22         <!-- 初始化连接大小 -->
    23         <property name="initialSize" value="${initialSize}"></property>
    24         <!-- 连接池最大数量 -->
    25         <property name="maxActive" value="${maxActive}"></property>
    26         <!-- 连接池最大空闲 -->
    27         <property name="maxIdle" value="${maxIdle}"></property>
    28         <!-- 连接池最小空闲 -->
    29         <property name="minIdle" value="${minIdle}"></property>
    30         <!-- 获取连接最大等待时间 -->
    31         <property name="maxWait" value="${maxWait}"></property>
    32     </bean>
    33     <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    34     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    35         <property name="dataSource" ref="dataSource" />
    36         <!-- 自动扫描mapping.xml文件 -->
    37         <property name="mapperLocations" value="classpath:wyp/ssm/demo/db/xml/*.xml"></property>
    38         <property name="typeAliasesPackage" value="wyp.ssm.demo.db.pojo" />  
    39     </bean>
    40     <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    41     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    42         <property name="basePackage" value="wyp.ssm.demo.db.mapper" />
    43         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    44     </bean>
    45     <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
    46     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    47         <property name="dataSource" ref="dataSource" />
    48     </bean>
    49 </beans>  
    spring-mybatis.xml

    4、SpringSecurity

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <beans:beans xmlns="http://www.springframework.org/schema/security"
      3     xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4     xsi:schemaLocation="http://www.springframework.org/schema/beans  
      5            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
      6            http://www.springframework.org/schema/security  
      7            http://www.springframework.org/schema/security/spring-security.xsd">
      8 
      9     <http pattern="/Scripts/**" security="none" />
     10     <http pattern="/Content/**" security="none" />
     11     <http pattern="/Account/Auth/Login" security="none" />
     12     <http entry-point-ref="authenticationEntryPoint">
     13         <!-- 替换默认的LoginFilter -->
     14         <custom-filter ref="customLoginFilter" position="FORM_LOGIN_FILTER" />
     15         <!-- 替换默认的LogoutFilter -->
     16         <custom-filter ref="customLogoutFilter" position="LOGOUT_FILTER" />
     17         <!-- 增加一个filter,这点与Acegi是不一样的,不能修改默认的filter了, 这个filter位于FILTER_SECURITY_INTERCEPTOR之前 -->
     18         <custom-filter ref="customSecurityFilter" before="FILTER_SECURITY_INTERCEPTOR" />
     19     </http>
     20     <beans:bean id="authenticationEntryPoint"
     21         class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
     22         <beans:constructor-arg name="loginFormUrl"
     23             value="/Account/Auth/Login" />
     24     </beans:bean>
     25     <!-- class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" 
     26         默认登录验证方式 -->
     27     <beans:bean id="customLoginFilter"
     28         class="wyp.ssm.demo._.UsernamePasswordAuthenticationFilterExtend">
     29         <!-- 校验登录是否有效的虚拟url -->
     30         <beans:property name="requiresAuthenticationRequestMatcher"
     31             ref="customLoginRequestMatcher" />
     32         <beans:property name="authenticationManager" ref="UserAuthenticationManager" />
     33         <beans:property name="usernameParameter" value="LoginAccount" />
     34         <beans:property name="passwordParameter" value="LoginPassword" />
     35         <beans:property name="authenticationSuccessHandler">
     36             <!-- 自定义登录成功后的处理handler -->
     37             <beans:bean
     38                 class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
     39                 <!-- 登录成功后的默认url -->
     40                 <beans:property name="defaultTargetUrl" value="/Home/Index" />
     41             </beans:bean>
     42         </beans:property>
     43         <beans:property name="authenticationFailureHandler">
     44             <beans:bean
     45                 class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
     46                 <!-- 登录失败后的默认Url -->
     47                 <beans:property name="defaultFailureUrl" value="/Account/Auth/Login" />
     48             </beans:bean>
     49         </beans:property>
     50     </beans:bean>
     51     <beans:bean id="customLoginRequestMatcher"
     52         class="org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter$FilterProcessUrlRequestMatcher">
     53         <beans:constructor-arg value="/Account/Auth/LoginDo/" />
     54     </beans:bean>
     55     <beans:bean id="customLogoutFilter"
     56         class="org.springframework.security.web.authentication.logout.LogoutFilter">
     57         <!-- 处理退出的虚拟url -->
     58         <beans:property name="logoutRequestMatcher" ref="customLogoutRequestMatcher" />
     59         <!-- 退出处理成功后的默认显示url -->
     60         <beans:constructor-arg index="0"
     61             value="/Account/Auth/Login" />
     62         <beans:constructor-arg index="1">
     63             <!-- 退出成功后的handler列表 -->
     64             <beans:array>
     65                 <beans:bean id="securityContextLogoutHandler"
     66                     class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler" />
     67             </beans:array>
     68         </beans:constructor-arg>
     69     </beans:bean>
     70     <beans:bean id="customLogoutRequestMatcher"
     71         class="org.springframework.security.web.authentication.logout.LogoutFilter$FilterProcessUrlRequestMatcher">
     72         <beans:constructor-arg value="/Account/Auth/Logout/" />
     73     </beans:bean>
     74     <!-- 一个自定义的filter,必须包含authenticationManager,accessDecisionManager,securityMetadataSource三个属性, 
     75         我们的所有控制将在这三个类中实现,解释详见具体配置 -->
     76     <beans:bean id="customSecurityFilter"
     77         class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
     78         <!-- 针对当前系统里所有可以访问的资源进行授权操作 -->
     79         <beans:property name="securityMetadataSource" ref="UrlSecurityMetadataSource" />
     80         <!-- 针对登录用户进行授权,同时验证登录用户名和密码是否合法 -->
     81         <beans:property name="authenticationManager" ref="UserAuthenticationManager" />
     82         <!-- 访问决策器,决定某个用户是否有足够的权限去访问某个资源 -->
     83         <beans:property name="accessDecisionManager" ref="UserUrlAccessDecisionManager" />
     84     </beans:bean>
     85     <!-- 资源数据定义,将所有的资源和权限对应关系建立起来,即定义某一资源可以被哪些角色访问 -->
     86     <beans:bean id="UrlSecurityMetadataSource" init-method="loadResourceDefine"
     87         class="wyp.ssm.demo._.FilterInvocationSecurityMetadataSourceImpl">
     88     </beans:bean>
     89     <!-- 验证配置 , 认证管理器,实现用户认证的入口,主要实现UserDetailsService接口即可 -->
     90     <authentication-manager alias="UserAuthenticationManager">
     91         <authentication-provider user-service-ref="UserNameUserDetailService">
     92             <password-encoder ref="UserPasswordEncoder">
     93                 <salt-source user-property="salt"/>  
     94             </password-encoder>
     95         </authentication-provider>
     96     </authentication-manager>
     97     <!-- 通过登录名称从数据库中得到当前登录用户的信息和他所拥有的权限 -->
     98     <beans:bean id="UserNameUserDetailService" class="wyp.ssm.demo._.UserDetailServiceImpl"></beans:bean>
     99     <!-- 通过登录名称从数据库中得到当前登录用户的信息验证登录密码是否正确 -->
    100     <beans:bean id="UserPasswordEncoder"
    101         class="wyp.ssm.demo._.MessageDigestPasswordEncoderImpl">
    102         <beans:constructor-arg name="algorithm" value="md5"></beans:constructor-arg>
    103     </beans:bean>
    104     <!-- 用户访问URL时验证权限 -->
    105     <beans:bean id="UserUrlAccessDecisionManager"
    106         class="wyp.ssm.demo._.AccessDecisionManagerImpl"></beans:bean>
    107     <!-- 免登陆过滤器 -->
    108 </beans:beans>
    spring-security.xml

    5、jdbc.properties

     1 driver=com.mysql.jdbc.Driver
     2 url=jdbc:mysql://192.168.7.55:13306/program_shopcart?useUnicode=true&characterEncoding=utf8
     3 username=root
     4 password=qwer1234
     5 #定义初始连接数  
     6 initialSize=0
     7 #定义最大连接数  
     8 maxActive=20
     9 #定义最大空闲  
    10 maxIdle=20
    11 #定义最小空闲  
    12 minIdle=1
    13 #定义最长等待时间  
    14 maxWait=60000
    jdbc.properties

    6、web.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
     5 
     6     <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
     7     <context-param>
     8         <param-name>contextConfigLocation</param-name>
     9         <param-value>classpath:spring-config.xml</param-value>
    10     </context-param>
    11     <!-- Spring监听器 -->
    12     <listener>
    13         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    14     </listener>
    15     
    16     <!-- 防止Spring内存溢出监听器 -->  
    17     <listener>  
    18         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
    19     </listener>
    20 
    21     <!-- Processes application requests -->
    22     <servlet>
    23         <servlet-name>springMVCServlet</servlet-name>
    24         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    25         <init-param>
    26             <param-name>contextConfigLocation</param-name>
    27             <!-- 修改spring mvc 表示层默认配置文件的路径 -->
    28             <param-value>classpath:spring-mvc.xml</param-value>
    29         </init-param>
    30         <load-on-startup>1</load-on-startup>
    31         <async-supported>true</async-supported>
    32     </servlet>
    33     
    34     <!-- url-pattern=/*必须加* -->
    35     <servlet-mapping>
    36         <servlet-name>springMVCServlet</servlet-name>
    37         <url-pattern>/*</url-pattern>
    38     </servlet-mapping>
    39     
    40     <!-- spring mvc security config -->
    41     <filter>  
    42         <filter-name>springSecurityFilterChain</filter-name>  
    43         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    44         <async-supported>true</async-supported>
    45     </filter>  
    46     <filter-mapping>  
    47         <filter-name>springSecurityFilterChain</filter-name>  
    48         <url-pattern>/*</url-pattern>
    49     </filter-mapping>
    50     
    web.xml
  • 相关阅读:
    Hibernate-查询缓存
    Hibernate-二级缓存 sessionFactory
    Hibernate-二级缓存策略
    Hibernate-一级缓存session
    缓存和连接池的区别
    Hibernate-一对多的关系维护
    Hibernate-缓存
    Java基础-jdk动态代理与cglib动态代理区别
    Java基础-CGLIB动态代理
    Java基础-静态代理与动态代理比较
  • 原文地址:https://www.cnblogs.com/qiyebao/p/5238190.html
Copyright © 2011-2022 走看看