各种配置大全

mybatis-config.xml配置

properties?, settings?, typeAliases?, typeHandlers?, objectFactory?, objectWrapperFactory?, reflectorFactory?, plugins?, environments?, databaseIdProvider?, mappers?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <properties resource="db.properties">
        
    </properties>
    
    <typeAliases>
        <package name="com.xsh.pojo"></package>
    </typeAliases>

    <typeHandlers>
        <typeHandler handler="com.xsh.typehandler.PasswordHandler" javaType="com.xsh.pojo.Password"></typeHandler>
    </typeHandlers>
    
    <environments default="develoment">
        <environment id="develoment">
            <transactionManager type="JDBC"></transactionManager>
            <dataSource type="POOLED">
                <property name="driver" value="${jdbc.driver}"></property>
                <property name="url" value="${jdbc.url}"></property>
                <property name="username" value="${jdbc.username}"></property>
                <property name="password" value="${jdbc.password}"></property>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <package name="com.xsh.mapper"></package>
    </mappers>
</configuration>

druid.properties配置

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///user?useSSL=false&characterEncoding=utf8
jdbc.username=root
jdbc.password=123456
jdbc.initialSize=1
jdbc.minIdle=1
jdbc.maxActive=20

jdbc.maxWait=60000

jdbc.timeBetweenEvictionRunsMillis=60000

jdbc.minEvictableIdleTimeMillis=300000

jdbc.validationQuery=SELECT 'x'
jdbc.testWhileIdle=true
jdbc.testOnBorrow=false
jdbc.testOnReturn=false

mapper.xml配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper nameplace="com.xsh.mapper.xxxMapper">


</mapper>

applicationContext.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:property-placeholder location="classpath:druid.properties"/>

    <!--数据库-->
    <bean id="datasource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="minIdle" value="${jdbc.minIdle}"/>
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="maxWait" value="${jdbc.maxWait}"/>
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
        <property name="validationQuery" value="${jdbc.validationQuery}"/>
        <property name="testOnReturn" value="${jdbc.testOnReturn}"/>
        <property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
        <property name="testOnBorrow" value="${jdbc.testOnBorrow}"/>
    </bean>
    <!--sqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="datasource"/>
        <property name="mapperLocations" value="classpath:com/xsh/mapper/*.xml"/>
        <!--分页插件-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>reasonable=true</value>
                    </property>
                </bean>
            </array>
        </property>
        <!--驼峰命名转换-->
        <property name="configuration">
            <array>
                <bean class="org.apache.ibatis.session.Configuration">
                    <property name="mapUnderscoreToCamelCase" value="true"/>
                </bean>
            </array>
        </property>
        <property name="typeAliasesPackage" value="com.xsh.pojo"/>
    </bean>

    <!--自动生成dao-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xsh.mapper"/>
    </bean>

    <context:component-scan base-package="com.xsh">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--注解驱动-->
    <!--注册alibaba的json转换器-->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <!--导入shiro配置文件的内容-->
    <import resource="application-shiro.xml"/>
</beans>

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="com.xsh" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--注册文件上传解析器-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="2097152"/>
    </bean>
    <mvc:annotation-driven/>

    <mvc:default-servlet-handler/>

    <!--异常解析器-->
    <bean class="com.xsh.exception_resolver.ExceptionResolver"/>
    <!--声明shiro的注解开发-->
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />

    <aop:config />

    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager"/>
    </bean>
</beans>

shiro.ini配置

[users]
root=123456,admin
[roles]
admin=*

[main]
#声明自定义的Realm
realm=com.xsh.realm.Realm
#将自定义的Realm注册给 核心控制者:Securitymanager
securityManager.realms=$realm

[urls]
/user/checkLogin=anon
/user/logout=logout

applicationContext_shiro.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">
    <!--spring集成shiro部分-->

    <!--realm-->
    <bean id="realm" class="com.xsh.realm.Realm">
        <property name="userService" ref="userServiceImpl"/>
        <property name="roleService" ref="roleServiceImpl"/>
        <property name="permissionService" ref="permissionServiceImpl"/>
        <!--密码匹配器-->
        <property name="credentialsMatcher">
            <bean class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
                <property name="hashAlgorithmName" value="Sha-256"/>
                <property name="hashIterations" value="10000"/>
                <property name="storedCredentialsHexEncoded" value="false"/>
            </bean>
        </property>
    </bean>

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

    <!--filter-->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="/user/login"/>
        <property name="unauthorizedUrl" value="/user/unauthorized"/>
        <property name="filterChainDefinitions">
            <value>
                /user/usersPage=authc,roles["admin"]
                /user/user=authc
                /user/logout=logout
            </value>
        </property>
    </bean>
</beans>

web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <servlet>
        <servlet-name>servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:mvc.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <!--验证码-->
    <servlet>
        <servlet-name>cap</servlet-name>
        <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
        <init-param>
            <param-name>kaptcha.border</param-name>
            <param-value>no</param-value>
        </init-param>
        <init-param>
            <param-name>kaptcha.textproducer.char.length</param-name>
            <param-value>4</param-value>
        </init-param>
        <init-param>
            <param-name>kaptcha.session.key</param-name>
            <param-value>captcha</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>cap</servlet-name>
        <url-pattern>/iocontroller/captcha</url-pattern>
    </servlet-mapping>
    <!-- rest过滤器,不支持put、delete的浏览器默认会将他们转为get,所以通过如下过滤器来解决此问题
     可以定义一个method="post"的form,附加一个名为"_method"的请求参数(隐藏域),即可模拟put,delete 请求方式
    -->
    <filter>
        <filter-name>httpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>httpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!--编码-->
    <filter>
        <filter-name>encoding</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>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--shiro-->
    <!--<filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>-->
    <!--通知工厂里的shiroFilter开始工作-->
    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- 在项目启动时,加载web-info 或 classpath下的 shiro.ini ,并构建WebSecurityManager。
         构建所有配置中使用的过滤器链(anon,authc等),ShiroFilter会获取此过滤器链
    -->
    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:beans.xml</param-value>
    </context-param>
</web-app>

applicationContext_redis.xml配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:property-placeholder location="classpath:jedis.properties"/>

    <!-- 连接池配置 -->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!-- 最多空闲连接数 -->
        <property name="maxIdle" value="1"/>
        <!-- 最多有多少连接 -->
        <property name="maxTotal" value="5"/>
        <property name="minIdle" value="1"></property>
        <!-- 连接数用完时,是否阻塞,阻塞超过maxWaitMillis会抛出异常 -->
        <property name="blockWhenExhausted" value="true" />
        <!-- 检出连接时,最大等待时长 -->
        <property name="maxWaitMillis" value="30000" />
        <!-- 在检出时是否检测 -->
        <property name="testOnBorrow" value="false" />
        <!-- 空闲时是否检测连接是否可用 -->
        <property name="testWhileIdle" value="false"></property>
        <!-- Evict=驱逐  连接至少要空闲多少时间才会成为可以被驱逐线程扫描并移除 -->
        <property name="minEvictableIdleTimeMillis" value="60000"></property>
        <!-- 驱逐线程 两次驱逐之间要sleep的时间 如果小于0,则不会有驱逐线程,则minEvictableIdleTimeMillis无效-->
        <property name="timeBetweenEvictionRunsMillis" value="30000"></property>
        <!-- 驱逐线程每次最多扫描几个连接 -->
        <property name="numTestsPerEvictionRun" value="3"></property>
        <!-- last in first out 检出策略 后入先出  或 先入先出 -->
        <property name="lifo" value="true"></property>
    </bean>

     <!--集群配置-->
     <!--为 redisClusterConfiguration定制参数配置-->
    <!--<bean id="propertiesPropertySource" class="org.springframework.core.env.PropertiesPropertySource">
        <constructor-arg index="0" type="java.lang.String" value="redisParam"></constructor-arg>
        <constructor-arg index="1" type="java.util.Properties">
            <props>
                &lt;!&ndash; 集群中的所有或部分节点ip:port &ndash;&gt;
                <prop key="spring.redis.cluster.nodes">192.168.43.128:2001,192.168.43.128:2004</prop>
                &lt;!&ndash;
                        默认为5,连接不到集群时,重试次数
                &ndash;&gt;
                <prop key="spring.redis.cluster.max-redirects">5</prop>
            </props>
        </constructor-arg>
    </bean>
    <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
        <constructor-arg name="propertySource" ref="propertiesPropertySource"/>
    </bean>

    <bean id="jedisConnectionFactory"
          class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <constructor-arg name="clusterConfig" ref="redisClusterConfiguration"></constructor-arg>
        <constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
    </bean>-->

     <!--连接Factory-->
    <bean id="jedisConnectionFactory"
          class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <!-- Redis主机 -->
        <property name="hostName" value="192.168.43.128"></property>
        <property name="port" value="1998"></property>
        <!-- 连接池配置信息 -->
        <property name="poolConfig" ref="jedisPoolConfig"></property>
    </bean>

    <!-- 如果没有设置序列化,则默认使用DefaultSerializer。
		 声明序列化组件
    -->
    <bean id="ss" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    <bean id="jacks" class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
    <bean class="com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer" id="fast"></bean>
    <!-- RedisTemplate:核心组件 -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
          p:connectionFactory-ref="jedisConnectionFactory"
          p:keySerializer-ref="ss"
          p:hashKeySerializer-ref="ss"
          p:hashValueSerializer-ref="fast"
          p:stringSerializer-ref="ss"
          p:valueSerializer-ref="fast"/>
    <bean id="sessionRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
          p:connectionFactory-ref="jedisConnectionFactory"
          p:keySerializer-ref="ss"/>
</beans>

applicationContext_ws.xml配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:ws="http://cxf.apache.org/jaxws"
       xmlns:rs="http://cxf.apache.org/jaxrs"
       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://cxf.apache.org/jaxws
                           http://cxf.apache.org/schemas/jaxws.xsd
                           http://cxf.apache.org/jaxrs
                           http://cxf.apache.org/schemas/jaxrs.xsd">
    <rs:server>
        <rs:serviceBeans>
            <bean class="com.xsh.service.impl.JobServiceImpl"/>
        </rs:serviceBeans>

        <rs:providers>
            <bean class="com.alibaba.fastjson.support.jaxrs.FastJsonProvider"/>
            <bean id="sf" class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter">
                <!-- 指定允许哪些域访问,默认:"*",即所有域都可以访问 -->
                <property name="allowOrigins">
                    <list>
                        <value>http://localhost:9090</value>
                    </list>
                </property>
                <!-- 允许其他域 携带本域cookie -->
                <property name="allowCredentials" value="true"/>
            </bean>
        </rs:providers>
    </rs:server>
</beans>

applicationContext_client.xml配置(soap协议形式)

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:ws="http://cxf.apache.org/jaxws"
       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://cxf.apache.org/jaxws
                           http://cxf.apache.org/schemas/jaxws.xsd">

    <context:component-scan base-package="com.xsh"/>
    <!-- webservice( Interface ) 客户端纳入工厂 -->
    <ws:client id="ws"
               serviceClass="com.xsh.service.WebServiceImpl"
               address="http://localhost:8080/webservice/ws/advice?wsdl"></ws:client>


    <!-- 将webservice 的客户端任意注入到需要rpc的本地业务中 -->

</beans>

applicationContext_quartz.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: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">
    <import resource="classpath:applicationContext.xml"/>
    <!--任务-->
    <!--<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="job"/>
        <property name="group" value="jobGroup"/>
        <property name="jobClass" value="com.xsh.job.MyJob"/>
        <property name="durability" value="true"/>
    </bean>-->

    <!--触发器1-->
    <!--<bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="trigger"/>
        <property name="group" value="triggerGroup"/>
        <property name="jobDetail" ref="jobDetail"/>
        <property name="cronExpression" value="*/3 * * * * ?"/>
    </bean>-->
    <!--触发器2-->
    <!--<bean id="trigger2" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="trigger"/>
        <property name="group" value="triggerGroup2"/>
        <property name="jobDetail" ref="jobDetail"/>
        <property name="cronExpression" value="*/2 * * * * ?"/>
    </bean>-->
    <!--调度器-->
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <!--<property name="triggers">
            <list>
                <ref bean="trigger"/>
                <ref bean="trigger2"/>
            </list>
        </property>-->
        <property name="quartzProperties">
            <value>
                # 指定调度器名称,实际类型为:QuartzScheduler
                org.quartz.scheduler.instanceName = MyScheduler78
                # 指定连接池
                org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
                # 连接池线程数量
                org.quartz.threadPool.threadCount = 11
                # 优先级
                org.quartz.threadPool.threadPriority = 5
                # 默认存储在内存中
                #org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
                #持久化
                org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
                #quartz表的前缀
                org.quartz.jobStore.tablePrefix = QRTZ_
            </value>
        </property>
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <import resource="classpath:applicationContext_ws.xml"/>
</beans>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值