SSJ的一些配置 jdbc.properties+applicationContext.xml+*-mvc.xml+*-shiro.xml

jdbc.properties

jdbc.username=root
jdbc.password=root
jdbc.url=jdbc:mysql://127.0.0.1:3306/数据库名?createDatabaseIfNotExist=true&characterEncoding=utf8
jdbc.driverClassName=com.mysql.jdbc.Driver

applicationContext.xml

<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       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/tx
         http://www.springframework.org/schema/tx/spring-tx.xsd
         http://www.springframework.org/schema/data/jpa
         http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <context:property-placeholder location="classpath:jdbc.properties" />
    <context:component-scan base-package="cn.itsource.aisell.service"/>

    <!-- 配置连接池 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <!--连接数据4个属性 -->
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <!--maxActive: 最大连接数量 -->
        <property name="maxActive" value="150" />
        <!--minIdle: 最小空闲连接 -->
        <property name="minIdle" value="5" />
        <!--maxIdle: 最大空闲连接 -->
        <property name="maxIdle" value="20" />
        <!--initialSize: 初始化连接 -->
        <property name="initialSize" value="30" />
        <!-- 用来配置数据库断开后自动连接的 -->
        <!-- 连接被泄露时是否打印 -->
        <property name="logAbandoned" value="true" />
        <!--removeAbandoned: 是否自动回收超时连接 -->
        <property name="removeAbandoned" value="true" />
        <!--removeAbandonedTimeout: 超时时间(以秒数为单位) -->
        <property name="removeAbandonedTimeout" value="10" />
        <!--maxWait: 超时等待时间以毫秒为单位 1000等于60秒 -->
        <property name="maxWait" value="1000" />
        <!-- 在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位. -->
        <property name="timeBetweenEvictionRunsMillis" value="10000" />
        <!-- 在每次空闲连接回收器线程(如果有)运行时检查的连接数量 -->
        <property name="numTestsPerEvictionRun" value="10" />
        <!-- 1000 * 60 * 30 连接在池中保持空闲而不被空闲连接回收器线程 -->
        <property name="minEvictableIdleTimeMillis" value="10000" />
        <property name="validationQuery" value="SELECT NOW() FROM DUAL" />
    </bean>

    <!-- 集成hibernate的jpa功能 -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!--待扫描的实体类包,不再需要persistence.xml了 -->
        <property name="packagesToScan" value="cn.itsource.aisell.domain" />
        <!-- 3.配置JPA的实现 -->
        <!-- private JpaVendorAdapter jpaVendorAdapter; -->
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <!-- org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter -->
                <!-- private boolean showSql = false;是否显示sql语句 -->
                <property name="showSql" value="true" />
                <!-- private boolean generateDdl = false;是否建表   validate-->
                <property name="generateDdl" value="false" />
                <!-- private String databasePlatform;原来方言 -->
                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
            </bean>
        </property>
    </bean>


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <!--开启注解事务的支持-->
    <tx:annotation-driven/>

    <!--springDatajpa特有的配置-->
    <jpa:repositories base-package="cn.itsource.aisell.repository"
                      entity-manager-factory-ref="entityManagerFactory"
                      transaction-manager-ref="transactionManager"/>

    <!-- 引入shiro.xml文件-->
    <import resource="classpath:applicationContext-shiro.xml"/>
</beans>

applicationContext-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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:component-scan base-package="cn.itsource.aisell.web.controller"/>

    <context:component-scan base-package="cn.afterturn.easypoi.view"/>
    <!-- 你返回逻辑视图的时候,永远先去找类对外暴露的资源接口,如果找到了则执行,如果没找到则最后执行视图解析器-->
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
        <property name="order" value="1"/>
    </bean>

    <!--开启springmvc特有注解的支持-->
    <!-- Spring MVC 配置 -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <!--解决IEjson输出乱码问题-->
                        <value>application/json; charset=UTF-8</value>
                        <value>application/x-www-form-urlencoded; charset=UTF-8</value>
                    </list>
                </property>
                <!-- No serializer:配置 objectMapper 为我们自定义扩展后的 CustomMapper,解决了返回对象有关系对象的报错问题 -->
                <property name="objectMapper">
                    <bean class="cn.itsource.aisell.common.CustomMapper"></bean>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <!--静态资源放行-->
    <mvc:default-servlet-handler/>
    <!--视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--配置上传解析器-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10485760"/>
    </bean>
</beans>

applicationContext-shiro.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!--spring管理shiro的核心对象-->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="itsourceRealm"/>
    </bean>


    <!--配置自定义realm-->
    <bean id="itsourceRealm" class="cn.itsource.aisell.realm.ItsourceRealm">
        <!--密码匹配器-->
        <property name="credentialsMatcher">
            <bean class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
                <property name="hashAlgorithmName" value="MD5"/>
                <property name="hashIterations" value="10"/>
            </bean>
        </property>
    </bean>

    <!--
        shiro的核心bean
        注意: 该bean的id必须要和web.xml中代理过滤器的名字一致,否则要报错

    -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <!--如果你没有认证通过,直接跳到loginUrl对应的页面-->
        <property name="loginUrl" value="/login/login.jsp"/>
        <!--登录成功之后,跳转的指定的界面-->
        <property name="successUrl" value="/login/success.jsp"/>

       <!-- 如果没有对应的权限则跳到unauthorizedUrl对应的界面-->
        <property name="unauthorizedUrl" value="/login/unauthorized.jsp"/>
       <!-- 配置过滤器链-->
        <!--
        这种方式真实开发不用,因为数据写死了的,灵活性较差
         <property name="filterChainDefinitions">
             <value>
                     anon:匿名过滤器,直接放行
                     authc:必须认证通过之后,才能放行
                     logout:登出
                 /s/login.jsp = anon
                 /login=anon
                 /logout=logout
                 /employee/index=perms["employee:*"]
                 /dept/index=perms["dept:index"]  访问/dept/index必须要拥有dept:index权限
                /** = authc
            </value>
        </property>
        -->
       <property name="filterChainDefinitionMap" ref="filterChainDefinitionMap"/>
        <!--自定义过滤器权限-->
        <property name="filters">
            <map>
                <entry key="itsourceFilter">
                    <bean class="cn.itsource.aisell.realm.ItsourcePermissionsAuthorizationFilter"/>
                </entry>
            </map>
        </property>
    </bean>
    <bean id="chainDefinitionMap" class="cn.itsource.aisell.realm.ItsourceFilterChainDefinitionMap"/>
    <bean id="filterChainDefinitionMap" factory-bean="chainDefinitionMap" factory-method="createMap"/>
</beans>
发布了54 篇原创文章 · 获赞 9 · 访问量 841

猜你喜欢

转载自blog.csdn.net/qq_40629521/article/details/104081561
今日推荐