标签:des style blog http java 使用
配置web.xml,applicationContext.xml, spring-mvc.xml,applicationContext-shiro.xml,而且都有详细的说明。
Web.xml是web项目最基本的配置文件,看这个配置,可以快速知道web项目使用什么框架,它就像一个面板,切入我们想用的插件。
applicationContext.xml是spring的基本配置,主要配置数据源、JPA实体管理器工厂、事务
spring-mvc.xml是SpringMVC的配置,
applicationContext-shiro.xml是shiro的配置,主要配置securityManager、shiroFilter
Web.xml
applicationContext.xml
- <span style="font-size:18px"><?xml version="1.0"encoding="UTF-8"?>
- <beansxmlnsbeansxmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:cache="http://www.springframework.org/schema/cache"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/cache
- http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
- http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
- <context:annotation-config />
-
- <context:component-scanbase-packagecontext:component-scanbase-package="org.shiro.demo">
- <context:exclude-filter type="annotation"
- expression="org.springframework.stereotype.Controller"/>
- </context:component-scan>
-
- <context:property-placeholderlocationcontext:property-placeholderlocation="classpath:jdbc.properties" />
-
-
- <bean id="dataSource"class="com.jolbox.bonecp.BoneCPDataSource"
- destroy-method="close">
- <property name="driverClass"value="${jdbc.driverClassName}" />
- <property name="jdbcUrl"value="${jdbc.url}" />
- <property name="username"value="${jdbc.username}" />
- <property name="password"value="${jdbc.password}" />
- </bean>
-
- <bean id="entityManagerFactory"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource"ref="dataSource" />
- <property name="jpaVendorAdapter"ref="hibernateJpaVendorAdapter" />
- <property name="packagesToScan"value="org.shiro.demo.entity" />
-
- <property name="jpaProperties">
- <props>
- <propkeypropkey="hibernate.current_session_context_class">thread</prop>
- <propkeypropkey="hibernate.hbm2ddl.auto">update</prop>
- <propkeypropkey="hibernate.show_sql">false</prop>
- <propkeypropkey="hibernate.format_sql">false</prop>
-
- <propkeypropkey="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
-
- </props>
- </property>
- </bean>
-
- <bean id="hibernateJpaVendorAdapter"
- class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="databasePlatform"value="${hibernate.dialect}"/>
- </bean>
-
-
-
- <bean id="txManager"
- class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory"ref="entityManagerFactory" />
- </bean>
-
- <tx:annotation-driventransaction-managertx:annotation-driventransaction-manager="txManager" />
- </beans></span>
spring-mvc.xml
- <span style="font-size:18px"><?xml version="1.0"encoding="UTF-8"?>
- <beansxmlnsbeansxmlns="http://www.springframework.org/schema/beans"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- 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-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
-
- <mvc:annotation-driven />
- <context:component-scanbase-packagecontext:component-scanbase-package="org.shiro.demo.controller" />
-
- <mvc:view-controller path="/"view-name="redirect:/login"/>
-
-
- <mvc:resources mapping="/resources/**"location="/resources/" />
-
- <beanclassbeanclass="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix"value="/" />
- <property name="suffix"value=".jsp" />
- </bean>
-
- <beanclassbeanclass="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
- <property name="exceptionMappings">
- <props>
- <propkeypropkey="org.apache.shiro.authz.UnauthorizedException">/system/error</prop>
-
-
-
-
- </props>
- </property>
- </bean>
- </beans></span>
ehcache-shiro.xml
- <span style="font-size:18px"><?xml version="1.0"encoding="UTF-8"?>
- <beansxmlnsbeansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsd"
- default-lazy-init="true">
-
- <description>Shiro安全配置</description>
-
-
-
- <bean id="securityManager"
- class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
- <property name="realm"ref="shiroDbRealm" />
- <!-- <property name="sessionMode" value="native"/>
- <property name="sessionManager" ref="sessionManager"/>
- -->
- </bean>
-
-
- <bean id="myShiroEhcacheManager"class="org.apache.shiro.cache.ehcache.EhCacheManager">
- <property name="cacheManagerConfigFile"value="classpath:ehcache-shiro.xml"/>
- </bean>
-
- <beanidbeanid="shiroDbRealm"class="org.shiro.demo.service.realm.ShiroDbRealm"depends-on="baseService">
- <propertynamepropertyname="userService" ref="userService"/>
- </bean>
-
- <bean id="shiroFilter"
- class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
- <property name="securityManager"ref="securityManager" />
- <property name="loginUrl"value="/" />
- <property name="successUrl"value="/system/main" />
- <property name="unauthorizedUrl"value="/system/error" />
-
-
-
-
-
- <propertynamepropertyname="filterChainDefinitions">
- <value>
- /login = anon
- /validateCode = anon
- /** = authc
- </value>
- </property>
- </bean>
-
- <bean id="lifecycleBeanPostProcessor"
- class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
-
-
-
-
- <bean
- class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
- depends-on="lifecycleBeanPostProcessor" >
- <property name="proxyTargetClass"value="true" />
- </bean>
- <bean
- class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
- <property name="securityManager"ref="securityManager" />
- </bean>
-
-
- </beans></span>
将 Shiro 作为应用的权限基础 五:SpringMVC+Apache Shiro+JPA(hibernate)整合配置,布布扣,bubuko.com
将 Shiro 作为应用的权限基础 五:SpringMVC+Apache Shiro+JPA(hibernate)整合配置
标签:des style blog http java 使用
原文地址:http://www.cnblogs.com/hanxue112253/p/3850596.html