Ssm+apache shiro--configuration file

Source: Internet
Author: User
Tags session id

1,web.xml

  

<web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ Web-app_2_5.xsd "><!--add Contextconfiglocation, notify spring to Classpath to find ApplicationContext configuration file, otherwise default to Web-info-- ><context-param> <param-name>contextConfigLocation</param-name> <param-value> Classpath:applicationcontext.xml</param-value> </context-param> <servlet><servlet-name>i Mdispatchservlet</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>imdispatchservlet</ Servlet-name><!--match all requests by default--><url-pattern>*.do</url-pattern></servlet-mapping><filter> <filter-name>shiroFilter</filter-name><filter-class> org.springframework.web.filter.delegatingfilterproxy</filter-class><!--<init-param> This value defaults to False, Indicates that the life cycle is managed by Springapplicationcontext, and set to True indicates that the Servletcontainer is managed by the <param-name>targetfilterlifecycle</par am-name> <param-value>true</param-value> </init-param>--></filter><fil Ter-mapping><filter-name>shirofilter</filter-name><url-pattern>*.do</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>incl Ude</dispatcher> <dispatcher>ERROR</dispatcher></filter-mapping>
     <!--prevent spring memory overflow listener--<listener><listener-class> Org.springframework.web.util.introspectorcleanuplistener</listener-class></listener> <listener ><listener-class>org.springframework.web.context.contextloaderlistener</listener-class></ Listener><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><init-param > <param-name>forceEncoding</param-name> &LT;PARAM-VALUE&GT;TRUE&LT;/PARAM-VALUE&G T </init-param> </filter><filter-mapping><filter-name>encodingFilter</filter-name> <url-pattern>*.do</url-pattern></filter-mapping><!--Configuration Error page-<error-page>< Error-code>404</error-code><locatiOn>/error.jsp</location></error-page> <error-page><error-code>500</error-code> <location>/error.jsp</location></error-page> <session-config><session-timeout>30 </session-timeout></session-config> <!--default page--><welcome-file-list><welcome-file> Login.jsp</welcome-file></welcome-file-list></web-app>

2, the configuration file is divided into Applicationcontext.xml,spring-shiro.mxl,spring-mybatis.xml,encache-shiro.xml

Applicationcontext.xml Configure spring MVC and other content:

  

<!--spring MVC configuration--<mvc:annotation-driven/> &LT;MVC:default-servlet-handler/><!--Configuring static resource mappings
<mvc:resources location= "/assets/" mapping= "/assets/**"/> <mvc:resources location= "/js/" mapping= "/js/**"/ > <mvc:resources location= "/css/" mapping= "/css/**"/> <mvc:resources location= "/images/" mapping= "/image s/** "/>-<!--viewresolver configuration-<Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView" ></property> <property name= "prefix" value= "/web-inf/ jsp/"/> <property name=" suffix "value=". jsp "/> </bean> <!--scan Web related--<context : Component-scan base- Package= "Com.test.controller" ></context:component-scan> <!--file upload download related to <bean id= "Multipartresolver"class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name= "maxuploadsize" value = "50000" ></property> <property name= "maxinmemorysize" value= "4096" ></property> </bean&gt ; <!--Interceptor Configuration-<mvc:interceptors> <mvc:interceptor> <mvc:mapping path= "/**"/>
<!--No blocking connection--<mvc:exclude-mapping path= "/common/login.do*"/> <beanclass= "Com.test.LoginInterceptor"/> </mvc:interceptor> </mvc:interceptors> <beanclass= "Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" > <property name= " Defaulterrorview "value="/error.jsp "></property> </bean> <ImportResource= "Classpath:spring-mybatis.xml"/> <ImportResource= "Classpath:spring-shiro.xml"/></beans>

Spring-mybatis.xml configuration file contents;

  

<util:properties id= "jdbc" location= "classpath:jdbc.properties"/> <context:component-scan base- Package= "Com.test.service.impl"/> <!--Hikari DataSource use--<bean id= "DataSource"class= "Com.zaxxer.hikari.HikariDataSource" destroy-method= "shutdown" > <property name= "jdbcurl" value= "#{jdbc.admi Nurl} "/> <property name=" driverclassname "value=" #{jdbc.admindriver} "/> <property name=" Userna  Me "value=" #{jdbc.adminuser} "/> <property name=" password "value=" #{jdbc.adminpassword} "/> <!-- Configured to True when a read-only database is connected, guaranteed to be secure--<property name= "ReadOnly" value= "false"/> <!--the maximum length of time to wait for a connection pool to allocate connections (MS           ), a connection that is not available for this length of time occurs SqlException, default: 30 Seconds--<property name= "ConnectionTimeout" value= "30000"/> <!--The maximum length of time (in milliseconds) for a connected idle state, timeout is released (retired), default: 10 minutes--<property name= "IdleTimeout" value= "600000"/&gt         ; <!--a connected life time (milliseconds), timed out and not used then released (retired), default: 30 minutes, recommended setting is 30 seconds less than database timeout, refer to mysql wait_timeout parameter (show variables like '% timeout% ';)--<property name= "Maxlifetime" value= "1800000"/> <property name= "Maximumpool Size "Value="/>     </bean> <!--sqlsessionfactory Chemical plant Configuration--<bean id= "Sqlsessionfactory"  class= "Org.mybatis.spring.SqlSessionFactoryBean" > <!--inject connection pool--<property name= "DataSource" ref= "dat Asource "/> <!--Configure MySQL global profile--<property name=" configlocation "value=" classpath:mybatis-conf Iguration.xml "/> <!--scan the entity package using aliases--<!--<property name=" typealiasespackage "value=" com . test.entity "/>-<!--sweep face SQL configuration file Mapper file--<property name=" Mapperlocations "value=" class Path:com/test/mapper/*.xml "/> </bean> <!--sweeping DAO interface Pack--and <beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basepackage" value= "Com.test.dao" > </property> <property name= "Sqlsessionfactorybeanname" value= "Sqlsessionfactory" ></property> & Lt;/bean> <!--configuration Transaction--<bean id= "Txmanager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name= "DataSource" ref= " DataSource "></property> </bean> <!--Configure declarative transactions based on annotations, use annotation management 1, clear programming style 2, ensure transaction method execution time as short as possible 3, not interspersed with other network operation 4, Some write operations do not require transactions, read-only write write one piece of data, delete, more data, if the bulk operation is required. --<tx:annotation-driven transaction-manager= "Txmanager" proxy-target-class= "true"/> <tx:advice id= "Imadvice" transaction-manager= "Txmanager" > <tx:attributes> &L T;tx:method name= "find*" read-only= "true"/> <tx:method name= "add*" propagation= "REQUIRED" rollback- for= "Java.lang.Exception"/> <tx:method name= "update*" propagation= "REQUIRED"rollback- for= "Java.lang.Exception"/> <tx:method name= "delete*" propagation= "REQUIRED"rollback- for= "Java.lang.Exception"/> </tx:attributes> </tx:advice> <aop:config proxy-target-class= "true" > <aop:advisor advice-ref= "Imadvice"pointcut= "Within" (Com.test.service.impl. *) "/> </aop:config>

Spring-shiro.xml Configuration content:

<!--Configuring Custom realm--<bean id= "Myrealm"class= "Com.test.MyRealm" > <property name= "authorizationcachename" value= "Myshirocache"/> </bean> <!--security Manager--<bean id=" SecurityManager "class= "Org.apache.shiro.web.mgt.DefaultWebSecurityManager" > <property name= "Realm" ref= "Myrealm"/> < !--Cache--<property name= "CacheManager" ref= "CacheManager" ></property> <property name = "SessionManager" ref= "SessionManager"/> </bean> <!--session Manager---<bean id= "session Manager "class= "Org.apache.shiro.web.session.mgt.DefaultWebSessionManager" > <!--how often do you check the validity of the session--<p Roperty name= "Sessionvalidationinterval" value= "1800000"/> <!--session valid for half an hour (milliseconds)--&lt       ;p roperty name= "globalsessiontimeout" value= "1800000"/> <property name= "Sessiondao" ref= "SessionDAO"/> <!--session monitoring, can be multiple. --<property name= "Sessionlisteners" > <list> <ref bean= "customsessionlist Ener "/> </list> </property> <!--interval How much time check, not configured is 60 Minutes--<property NA Me= "Sessionvalidationscheduler" ref= "Sessionvalidationscheduler"/> <!--turn on detection, on by default, <property N Ame= "sessionvalidationschedulerenabled" value= "true"/> <!--delete invalid, the default is also on---<property name= "dele Teinvalidsessions "value=" true "/> <!--session cookie template--<property name=" Sessionidcookie "ref=" seSsionidcookie "/> <property name=" sessionidcookieenabled "value=" true "/> </bean> <!--session Validation Scheduler  --<bean id= "Sessionvalidationscheduler"class= "Org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler" > <!--interval how much time to check, not configured is 60 Minutes-- <property name= "Interval" value= "12000000"/> <property name= "SessionManager" ref= "SessionManager"/&G    T </bean> <!--session DAO--<bean id= "Sessiondao"class= "Org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO" > <property name= "Activesessionscachename" Value= "Activesessioncache"/> <property name= "CacheManager" ref= "CacheManager"/> <property name= " Sessionidgenerator "ref=" Sessionidgenerator "/> </bean> <bean id=" CacheManager "class= "Org.apache.shiro.cache.ehcache.EhCacheManager" > <property name= "cachemanagerconfigfile" value= "classpath: Ehcache-shiro.xml "/> </bean> <bean id=" Customsessionlistener "class= "Com.test.MySessionManager" ></bean> <!--cookie template--<bean id= "Sessionidcookie"class= "Org.apache.shiro.web.servlet.SimpleCookie" > <constructor-arg name= "name" value= "Imsid"/> <pro Perty name= "HttpOnly" value= "true"/> <property name= "MaxAge" value= "1800"/><!--units s--> </bean&    Gt <!--session ID Generator--<bean id= "Sessionidgenerator"class= "Org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator"/> <!--Shiro Filter Core--<bean id= "Shirofil terclass= "Org.apache.shiro.spring.web.ShiroFilterFactoryBean" > <!--Shiro Core Security interface, this property is required--<property Name= "SecurityManager" ref= "SecurityManager"/> <!--authentication failed, then jump to the login page configuration--<property name= "Login Url "value="/login.jsp "/> <!--permission authentication failed, then jump to the specified page--<property name=" Unauthorizedurl "value="/erro R.jsp "/> <!--Shiro Connection constraint configuration, that is, the definition of the filter chain--<property name=" Filterchaindefinitions "> &lt ;value> <!--anon for anonymous access, no authentication and authorization--/common**=Anon<!--AUTHC indicates that authentication is not required and cannot be accessed---/USER**=AUTHC</value> </property> </bean> <!--guaranteed bean execution for Shiro internal lifecycle functions --<bean id= "Lifecyclebeanpostprocessor" class= "Org.apache.shiro.spring.LifecycleBeanPostProcessor"/> &L t;!          --Open Shiro annotation--<bean class= "Org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on= "Lifecyclebeanpostprocessor"/> <bean class= " Org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor "> <property name=" SecurityManager "ref=" SecurityManager "/> </bean>

Encache-shiro.xml Cache Configuration:

<ehcache updatecheck= "false" Name= "Shirocache" > <Defaultcache maxelementsinmemory= "10000"Eternal= "false"Timetoidleseconds= "120"Timetoliveseconds= "120"Overflowtodisk= "false"diskpersistent= "false"Diskexpirythreadintervalseconds= "/>" <!--Myrealm Configure the name of the authentication authorization cache, explicitly specified--<cache name= "Myshirocache"maxelementsinmemory= "10000"Eternal= "false"Timetoidleseconds= "30"Timetoliveseconds= "0"Overflowtodisk= "false"diskpersistent= "false"Diskexpirythreadintervalseconds= "/></ehcache>"

 

Ssm+apache shiro--configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.