zoukankan      html  css  js  c++  java
  • Spring配置文件和SpringMVC配置文件 web.xml配置文件 保存自用

    话不多说,最近在周末自己抽时间写一些框架做的系统,当所有东西都需要自己配置时候发现自己压根记不住这么多类和路径,所以日常总结就变得尤为重要了
    db-config.properties 将配置文件常量提出来可多次使用

    hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
    hibernate.hbm2ddl.auto=none
    hibernate.show_sql=true
    hibernate.format_sql=true
    hibernate.query.substitutions=true 1, false 0
    hibernate.default_batch_fetch_size=16
    hibernate.max_fetch_depth=2
    hibernate.bytecode.use_reflection_optimizer=true
    #hibernate.cache.use_second_level_cache=true
    #hibernate.cache.use_query_cache=true
    #hibernate.cache.region.factory_class=org.hibernate.cache.EhCacheRegionFactory
    #net.sf.ehcache.configurationResourceName=/ehcache_hibernate.xml
    hibernate.cache.use_structured_entries=true
    hibernate.generate_statistics=true
    hibernate.enable_lazy_load_no_trans=true
    connection.provider_class = org.hibernate.c3p0.internal.C3P0ConnectionProvider
    hibernate.c3p0.min_size=5
    hibernate.c3p0.max_size=20
    hibernate.c3p0.timeout=300
    hibernate.c3p0.idle_test_period=3000
    hibernate.c3p0.max_statements=50
    hibernate.c3p0.validate=true
    hibernate.c3p0.acquire_increment=2
    connection.driver_class=com.mysql.jdbc.Driver

    connection.url=jdbc:mysql://localhost:3306/dormitory?autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=utf8
    connection.username=root
    connection.password=123456

    c3p0.minPoolSize=3
    c3p0.maxPoolSize=10
    c3p0.initialPoolSize=3
    c3p0.maxIdleTime=60
    c3p0.acquireIncrement=3
    c3p0.maxStatements=0
    c3p0.idleConnectionTestPeriod=60
    c3p0.acquireRetryAttempts=30
    c3p0.breakAfterAcquireFailure=false
    c3p0.testConnectionOnCheckout=false
    c3p0.testConnectionOnCheckin=false
    c3p0.debugUnreturnedConnectionStackTraces=true
    c3p0.unreturnedConnectionTimeout=90
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    spring-config.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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/task
    http://www.springframework.org/schema/task/spring-task-4.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <!-- 扫描相应的包然后 -->
    <context:annotation-config base-package="com.vrv.common.service"/>
    <context:annotation-config base-package="com.vrv.common.dao"/>
    <context:annotation-config base-package="com.vrv.system.dao"/>
    <context:annotation-config base-package="com.vrv.system.service"/>
    <context:annotation-config base-package="com.vrv.buss.service"/>
    <!-- properties文件配置 引入 -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:*-config.properties</value>
    </list>
    </property>
    </bean>
    <!-- 数据库配置 -->

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <!-- 指定连接数据库的驱动 -->
    <property name="driverClass" value="${connection.driver_class}"/>
    <!-- 指定连接数据库的URL -->
    <property name="jdbcUrl" value="${connection.url}" />
    <!-- 指定连接数据库的用户名 -->
    <property name="user" value="${connection.username}" />
    <!-- 指定连接数据库的密码 -->
    <property name="password" value="${connection.password}" />
    <!-- 指定连接数据库连接池的最大连接数 -->
    <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
    <!-- 指定连接数据库连接池的最小连接数 -->
    <property name="minPoolSize" value="${c3p0.minPoolSize}" />
    <!-- 指定连接数据库连接池的初始化连接数 -->
    <property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
    <!-- 指定连接数据库连接池的连接的最大空闲时间 -->
    <property name="maxIdleTime" value="${c3p0.maxIdleTime}" />

    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
    <property name="acquireIncrement">
    <value>${c3p0.acquireIncrement}</value>
    </property>
    <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
    如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
    <property name="maxStatements">
    <value>${c3p0.maxStatements}</value>
    </property>
    <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
    <property name="idleConnectionTestPeriod">
    <value>${c3p0.idleConnectionTestPeriod}</value>
    </property>
    <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
    <property name="acquireRetryAttempts">
    <value>${c3p0.acquireRetryAttempts}</value>
    </property>
    <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
    获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
    <property name="breakAfterAcquireFailure">
    <value>${c3p0.breakAfterAcquireFailure}</value>
    </property>
    <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
    等方法来提升连接测试的性能。Default: false -->
    <property name="testConnectionOnCheckout">
    <value>${c3p0.testConnectionOnCheckout}</value>
    </property>

    <!-- 配置断开连接自动自重连 -->
    <property name="testConnectionOnCheckin">
    <value>${c3p0.testConnectionOnCheckin}</value>
    </property>

    <!-- 泄漏 监控 -->
    <property name="unreturnedConnectionTimeout">
    <value>${c3p0.unreturnedConnectionTimeout}</value>
    </property>

    <property name="debugUnreturnedConnectionStackTraces">
    <value>${c3p0.debugUnreturnedConnectionStackTraces}</value>
    </property>

    </bean>

    <!-- 配置Spring的SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="packagesToScan">
    <list>
    <value>com.vrv.buss.entity.*</value>
    <value>com.vrv.common.entity.*</value>
    <value>com.vrv.system.entity.*</value>
    </list>
    </property>
    <!-- 配置数据库本地方言等等操作哦 -->
    <property name="hibernateProperties">
    <props>
    <prop key="javax.persistence.validation.mode">none</prop>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
    <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
    <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
    <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
    <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
    <prop key="hibernate.bytecode.use_reflection_optimizer"></prop>
    <prop key="hibernate.enable_lazy_load_no_trans">${hibernate.enable_lazy_load_no_trans}</prop>
    <prop key="connection.provider_class">${connection.provider_class}</prop>
    <!-- 开启查询缓存 -->
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <!-- 开启二级缓存 -->
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    <!-- 高速缓存提供程序 -->
    <!-- 由于spring也使用了Ehcache, 保证双方都使用同一个缓存管理器 -->
    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
    <!-- 最小连接数 -->
    <prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop>
    <!-- 最大连接数 -->
    <prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop>
    <!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
    <prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop>
    <!-- 每隔3000秒检查连接池里的空闲连接 ,单位是秒-->
    <prop key="hibernate.c3p0.idle_test_period">${hibernate.c3p0.idle_test_period}</prop>
    <!--查询的最大结果集 -->
    <prop key="hibernate.c3p0.max_statements">${hibernate.c3p0.max_statements}</prop>
    <!-- 每次都验证连接是否可用 -->
    <prop key="hibernate.c3p0.validate">${hibernate.c3p0.validate}</prop>
    <!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
    <prop key="hibernate.c3p0.acquire_increment">${hibernate.c3p0.acquire_increment}</prop>
    </props>
    </property>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--事务传播属性配置-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="del*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="find*" propagation="REQUIRED" />
    <tx:method name="get*" propagation="REQUIRED" />
    <tx:method name="apply*" propagation="REQUIRED" read-only="true"/>
    <tx:method name="*" propagation="REQUIRED" read-only="true"/>
    </tx:attributes>
    </tx:advice>
    <!-- 配置参与事务的类 定义事务切入点-->
    <aop:config>
    <aop:pointcut id="txPointcut" expression="execution(* com.vrv..service..*.*(..))" />
    <aop:advisor pointcut-ref="txAdvice" advice-ref="txPointcut" />
    </aop:config>

    <!-- 开启AOP监听 只对当前配置文件有效 -->
    <aop:aspectj-autoproxy expose-proxy="true" />


    <!-- 避免IE执行AJAX时,返回JSON出现下载文件 编码设置-->
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes">
    <list>
    <value>text/html;charset=UTF-8</value>
    </list>
    </property>
    </bean>

    <!-- cacheManager, 指定ehcache.xml的位置 -->
    <bean id="cacheManagerEhcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation">
    <value>classpath:ehcache.xml</value>
    </property>
    <!-- 由于hibernate也使用了Ehcache, 保证双方都使用同一个缓存管理器 -->
    <property name="shared" value="true"/>
    </bean>

    </beans>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    spring-mvc.xml springmvc的配置文件

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

    <!-- 定义扫描Controller包下的内容 -->
    <context:component-scan base-package="com.vrv.system.controller"/>
    <context:component-scan base-package="com.vrv.common.controller"/>
    <context:component-scan base-package="com.vrv.buss.controller"/>

    <!-- @Controller注解的使用前提配置 详细解释见(注.txt 1. )-->
    <mvc:annotation-driven />
    <!-- 加载静态文件 -->
    <mvc:resources location="/js/" mapping="/js/**" />
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/image/" mapping="/image/**" />
    <mvc:resources location="/font/" mapping="/font/**" />
    <!-- <context:annotation-config/> -->
    <!-- 对module包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能-->
    <context:component-scan base-package="module">
    </context:component-scan>

    <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

    <!-- 定义视图解析器,在视图模型前后添加前缀后缀 暂时只支持jsp后缀-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" /><!-- 路径前缀 -->
    <property name="suffix" value=".jsp" /><!-- 后缀 -->
    </bean>

    <!-- 系统错误转发配置[并记录错误日志] -->
    <bean
    class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="defaultErrorView" value="500"></property> <!-- 默认为500,系统错误(error.jsp) -->
    <property name="defaultStatusCode" value="404"></property>
    <property name="statusCodes"><!-- 配置多个statusCode -->
    <props>
    <prop key="error">500</prop> <!-- error.jsp -->
    </props>
    </property>
    </bean>

    <!-- 拦截器配置 -->
    <mvc:interceptors>
    <mvc:interceptor>
    <mvc:mapping path="/**"/>
    <bean class="com.vrv.system.interceptor.AuthInterceptor">
    <property name="excludeUrls">
    <list>
    <value>LoginController.do?login</value>
    </list>
    </property>
    </bean>
    </mvc:interceptor>
    </mvc:interceptors>
    </beans>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <display-name>comvrv</display-name>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:*-config.xml</param-value>
    </context-param>
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
    </context-param>
    <context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>6000</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>true</param-value>
    </init-param>
    <init-param>
    <param-name>sessionFactoryBeanName</param-name>
    <param-value>sessionFactory</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <filter>
    <filter-name>CharacterEncodingFilter</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>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
    <listener-class>
    org.springframework.web.util.IntrospectorCleanupListener
    </listener-class>
    </listener>
    <listener>
    <description>request监听器</description>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>CaptchaServlet</servlet-name>
    <servlet-class>com.vrv.system.CaptchaServlet</servlet-class>
    <load-on-startup>10</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>CaptchaServlet</servlet-name>
    <url-pattern>/captchaCode</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    <error-page>
    <error-code>404</error-code>
    <location>/pages/common/404.jsp</location>
    </error-page>
    <welcome-file-list>
    <welcome-file>/pages/system/login.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    当然这些配置文件在大一些东西全都做了封装,你只需要之后自己要用什么直接调用就行了,但是在个人学习过程中,我们还是需要懂得配置和必须掌握的,这有利于我们对整个框架的工作原理进行掌握。
    有句话说得好,不积硅步无以至千里!从小事做起,成长!希望这一周能够在工作之余自己将学生宿舍管理系统搭建起来!!加油
    虽然现在出现了点问题,但是明天一定会解决,还有十天参加秋招,加油,多积累,然后看关于linux知识,准备秋招!!加油!
    ---------------------
    作者:BigVolcano
    来源:CSDN
    原文:https://blog.csdn.net/baidu_34168157/article/details/77431048
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    iOS企业证书开发的APP证书过期时间监控
    事件冒泡,事件捕获
    倒计时
    获取多个div,点击第几个,显示第几个
    js继承
    javascript基础知识总结
    大型web系统高效应用方法(转载)
    数据库(内联,外联,交叉联)
    .net零碎基础知识点不完全小结
    C#的内存管理:堆、栈、托管堆与指针(转)
  • 原文地址:https://www.cnblogs.com/Jeely/p/10762392.html
Copyright © 2011-2022 走看看