springMVC+Hibernate,幾個配置文件 整理記錄。

1.applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:drools="http://drools.org/schema/drools-spring"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd 
 http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd
  http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
  default-lazy-init="true">

 <bean id="propertyConfigurer"
   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="locations">
    <list>
     <value>classpath:jdbc.properties</value>
    </list>
   </property>
  </bean>

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
   destroy-method="close">
   <property name="driverClassName" value="${jdbc.driverClassName}" />
   <property name="url" value="${jdbc.url}" />
   <property name="username" value="${jdbc.username}" />
   <property name="password" value="${jdbc.password}" />
   <property name="initialSize" value="${datasource.initialSize}" />
   <property name="maxActive" value="${datasource.maxActive}" />
   <property name="maxIdle" value="${datasource.maxIdle}" />
   <property name="minIdle" value="${datasource.minIdle}" />
   <property name="maxWait" value="${datasource.maxWait}" />
   <property name="defaultAutoCommit" value="${datasource.defaultAutoCommit}" />
   <property name="removeAbandoned" value="${datasource.removeAbandoned}" />
   <property name="removeAbandonedTimeout" value="${datasource.removeAbandonedTimeout}" />
  </bean>

 <!-- 配置sessionFactory -->
  <bean id="sessionFactory"
   class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
   <property name="dataSource">
    <ref bean="dataSource" />
   </property>
   <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">
      org.hibernate.dialect.Oracle9Dialect
     </prop>
     <prop key="hibernate.show_sql">false</prop>
     <prop key="hibernate.jdbc.batch_size">1000</prop>
    </props>
   </property>
   <property name="packagesToScan" value="com.test.main" />
   <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
  </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
       <property name="dataSource" ref="dataSource"/>
     </bean> 
    
 <!-- 定義事務管理器(聲明式的事務) -->
  <bean id="transactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory" />
  </bean>

 <context:component-scan base-package="com.test.main">
   <context:exclude-filter type="regex"
    expression=".*Controller$" />
  </context:component-scan>
  <context:annotation-config />


 

2.dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:drools="http://drools.org/schema/drools-spring"
  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-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd 
 http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd
  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
  http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
  default-lazy-init="true">


  <!-- ①:對web包中的全部類進行掃描,以完成Bean建立和自動依賴注入的功能 -->
  <context:component-scan base-package="com.test.main.dicom.web" />
  <context:component-scan base-package="com.test.main.core.web" />

 <!-- ②:啓動Spring MVC的註解功能,完成請求和註解POJO的映射 -->
  <bean
   class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
   <property name="messageConverters">
    <list>
     <ref bean="mappingJacksonHttpMessageConverter" />
    </list>
   </property>
  </bean>
  <bean id="mappingJacksonHttpMessageConverter"
   class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
  <bean id="viewResolver" class="com.test.main.core.system.MultipleViewResolver">
   <property name="resolvers">
    <map>
     <entry key="jsp">
      <bean
       class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
       <property name="prefix">
        <value>/WEB-INF/pages/</value>
       </property>
      </bean>
     </entry>
     <entry key="html">
      <bean id="excelViewResolver"
       class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix">
        <value>/WEB-INF/pages/</value>
       </property>
      </bean>
     </entry>
    </map>
   </property>
  </bean>
  <mvc:interceptors >     
    <mvc:interceptor>     
         <mvc:mapping path="/*/*" /> 
         <mvc:mapping path="/*/*/*" /> 
         <bean class="com.test.main.core.system.LogHandlerInterceptorAdapter"></bean>     
     </mvc:interceptor>     
 </mvc:interceptors>  
</beans>

3.web.xml

 


  

<?xml version="1.0" encoding="UTF-8"?>
 <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <welcome-file-list>
   <welcome-file>/login.jsp</welcome-file>
  </welcome-file-list>
  <!-- 控制中心 -->

 <servlet>
   <servlet-name>dispatcher</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet
   </servlet-class>
   <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>dispatcher</servlet-name>
   <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <servlet>
         <servlet-name>flex</servlet-name>
         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
     </servlet>

    <servlet-mapping>
         <servlet-name>flex</servlet-name>
         <url-pattern>/messagebroker/*</url-pattern>
     </servlet-mapping>
  
  <context-param>
   <param-name>webAppRootKey</param-name>
   <param-value>webapp.root</param-value>
  </context-param>
  <context-param>
   <param-name>log4jConfigLocation</param-name>
   <param-value>/WEB-INF/classes/log4j.properties</param-value>
  </context-param>
  <context-param>
   <param-name>log4jRefreshInterval</param-name>
   <param-value>60000</param-value>
  </context-param>
  <listener>
   <listener-class>org.springframework.web.util.Log4jConfigListener
   </listener-class>
  </listener>
  <listener>
         <listener-class>flex.messaging.HttpFlexSession</listener-class>
     </listener>

 
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
    /WEB-INF/config/applicationContext*.xml
   </param-value>
  </context-param>
  
  <!-- 配置url過濾器開始  -->
  <filter>  
        <filter-name>urlFilter</filter-name>  
        <filter-class>com.test.main.core.security.UrlFilter</filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>urlFilter</filter-name>  
        <url-pattern>*.do</url-pattern>  
    </filter-mapping>  
 <!--配置url過濾器結束 -->
  
  <!-- Hibernate Open Session In View filter-->
  <filter>
   <filter-name>hibernateOpenSessionInViewFilter</filter-name>
   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>  
          <param-name>flushMode</param-name>  
          <param-value>AUTO</param-value>  
       </init-param>
        <init-param>  
          <param-name>singleSession</param-name>  
           <param-value>true</param-value>  
      </init-param>  
 </filter>
  <filter-mapping>
   <filter-name>hibernateOpenSessionInViewFilter</filter-name>
   <url-pattern>*.do</url-pattern>
   <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  </filter-mapping>
  <filter>
   <filter-name>Set Character Encoding</filter-name>
   <filter-class>org.springframework.web.filter.CharacterEncodingFilter
   </filter-class>
   <init-param>
    <param-name>encoding</param-name>
    <param-value>utf8</param-value>
   </init-param>
  </filter>
  <filter-mapping>
   <filter-name>Set Character Encoding</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <!-- 配置spiring security 開始 --> 
    <filter>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
 <!-- 配置spiring security結束 -->  
 
  <listener>
   <listener-class>
    org.springframework.security.web.session.HttpSessionEventPublisher 
  </listener-class>
  </listener>

 <!-- session超時定義,單位爲分鐘 -->
  <session-config>
   <session-timeout>30</session-timeout>
  </session-config>

 <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener
   </listener-class>
  </listener>
  <listener>
   <listener-class>com.test.main.core.system.LoadConfiguration
   </listener-class>
  </listener>
  
  <!-- 自定義標籤 -->
  <jsp-config>
   <taglib>
    <taglib-uri>/cstmtag</taglib-uri>
    <taglib-location>/WEB-INF/tlds/cstmtag.tld</taglib-location>
   </taglib>
  </jsp-config>

 <!-- 出錯頁面定義 -->
  <error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/WEB-INF/pages/common/500.jsp</location>
  </error-page>
  <error-page>
   <error-code>500</error-code>
   <location>/WEB-INF/pages/common/500.jsp</location>
  </error-page>
  <error-page>
   <error-code>404</error-code>
   <location>/WEB-INF/pages/common/404.jsp</location>
  </error-page>
相關文章
相關標籤/搜索