<?xml version="1.0" encoding="UTF-8"?>
<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"
       xsi:schemaLocation="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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--读取配置文件-->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!--配置数据源-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${driver1}"></property>
        <property name="url" value="${url1}"></property>
        <property name="username" value="${username1}"></property>
        <property name="password" value="${password1}"></property>
    </bean>

    <!--配置sqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="typeAliasesPackage" value="com.xpx.pojo"></property>
    </bean>

    <!--扫描mapper-->
    <bean id="mapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
        <property name="basePackage" value="com.xpx.mapper"></property>
    </bean>

    <!--扫描service-->
    <context:component-scan base-package="com.xpx.service.impl"/>

    <!--配置shiro-->


    <!--配置加密信息-->
    <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
        <property name="hashAlgorithmName" value="md5"></property>
        <property name="hashIterations" value="2"></property>
    </bean>

    <!--配置自定Realm-->
    <bean id="loginAdmin" class="com.xpx.realm.AdminRealm">
        <property name="credentialsMatcher" ref="credentialsMatcher"></property>
    </bean>

    <!--配置securityManager-->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realms" ref="loginAdmin"></property>
    </bean>

    <!--配置ShiroFilterFactoryBean-->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="loginUrl" value="/login"></property>
        <property name="successUrl" value="/success.jsp"></property>
        <property name="unauthorizedUrl" value="/error.jsp"></property>

        <property name="securityManager" ref="securityManager"></property>

        <property name="filterChainDefinitions">
            <value>
                /login=authc
                /**=anon
            </value>
        </property>
    </bean>


    <bean id="authc" class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">

        <property name="usernameParam" value="uname"></property>

        <property name="passwordParam" value="pwd"></property>

        <property name="rememberMeParam" value="rm"></property>


    </bean>

</beans>