话不多说,最近在周末自己抽时间写一些框架做的系统,当所有东西都需要自己配置时候发现自己压根记不住这么多类和路径,所以日常总结就变得尤为重要了
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
spring-config.xml 引入申明的常量配置文件
<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"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:*-config.propertiesvalue>
list>
property>
bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${connection.driver_class}"/>
<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}" />
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}value>
property>
<property name="maxStatements">
<value>${c3p0.maxStatements}value>
property>
<property name="idleConnectionTestPeriod">
<value>${c3p0.idleConnectionTestPeriod}value>
property>
<property name="acquireRetryAttempts">
<value>${c3p0.acquireRetryAttempts}value>
property>
<property name="breakAfterAcquireFailure">
<value>${c3p0.breakAfterAcquireFailure}value>
property>
<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>
<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">noneprop>
<prop key="hibernate.dialect">${hibernate.dialect}prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}prop>
<prop key="hibernate.format_sql">trueprop>
<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">trueprop>
<prop key="hibernate.cache.use_second_level_cache">trueprop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactoryprop>
<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>
<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>
<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:aspectj-autoproxy expose-proxy="true" />
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8value>
list>
property>
bean>
<bean id="cacheManagerEhcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:ehcache.xmlvalue>
property>
<property name="shared" value="true"/>
bean>
beans>
spring-mvc.xml springmvc的配置文件
<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">
<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"/>
<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:component-scan base-package="module">
context:component-scan>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<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>
<property name="defaultStatusCode" value="404">property>
<property name="statusCodes">
<props>
<prop key="error">500prop>
props>
property>
bean>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.vrv.system.interceptor.AuthInterceptor">
<property name="excludeUrls">
<list>
<value>LoginController.do?loginvalue>
list>
property>
bean>
mvc:interceptor>
mvc:interceptors>
beans>
web.xml
<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>comvrvdisplay-name>
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:*-config.xmlparam-value>
context-param>
<context-param>
<param-name>log4jConfigLocationparam-name>
<param-value>classpath:log4j.propertiesparam-value>
context-param>
<context-param>
<param-name>log4jRefreshIntervalparam-name>
<param-value>6000param-value>
context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListenerlistener-class>
listener>
<filter>
<filter-name>openSessionInViewFilterfilter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilterfilter-class>
<init-param>
<param-name>singleSessionparam-name>
<param-value>trueparam-value>
init-param>
<init-param>
<param-name>sessionFactoryBeanNameparam-name>
<param-value>sessionFactoryparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>openSessionInViewFilterfilter-name>
<url-pattern>*.dourl-pattern>
filter-mapping>
<filter>
<filter-name>CharacterEncodingFilterfilter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
<init-param>
<param-name>encodingparam-name>
<param-value>UTF-8param-value>
init-param>
<init-param>
<param-name>forceEncodingparam-name>
<param-value>trueparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>CharacterEncodingFilterfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<servlet>
<servlet-name>dispatcherservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:spring-mvc.xmlparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>dispatcherservlet-name>
<url-pattern>*.dourl-pattern>
servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
listener-class>
listener>
<listener>
<description>request监听器description>
<listener-class>org.springframework.web.context.request.RequestContextListenerlistener-class>
listener>
<servlet>
<servlet-name>CaptchaServletservlet-name>
<servlet-class>com.vrv.system.CaptchaServletservlet-class>
<load-on-startup>10load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>CaptchaServletservlet-name>
<url-pattern>/captchaCodeurl-pattern>
servlet-mapping>
<session-config>
<session-timeout>30session-timeout>
session-config>
<error-page>
<error-code>404error-code>
<location>/pages/common/404.jsplocation>
error-page>
<welcome-file-list>
<welcome-file>/pages/system/login.jspwelcome-file>
welcome-file-list>
web-app>
当然这些配置文件在大一些东西全都做了封装,你只需要之后自己要用什么直接调用就行了,但是在个人学习过程中,我们还是需要懂得配置和必须掌握的,这有利于我们对整个框架的工作原理进行掌握。
有句话说得好,不积硅步无以至千里!从小事做起,成长!希望这一周能够在工作之余自己将学生宿舍管理系统搭建起来!!加油
虽然现在出现了点问题,但是明天一定会解决,还有十天参加秋招,加油,多积累,然后看关于linux知识,准备秋招!!加油!