设为首页 收藏本站
查看: 547|回复: 0

[经验分享] Struts2+Spring+hibernate之jndi分布式数据库搭建-weblogic中间件

[复制链接]

尚未签到

发表于 2017-2-18 10:38:19 | 显示全部楼层 |阅读模式
1、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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>test</display-name>
<distributable />
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<filter>  
  <filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- shiro security filter 要配置在struts2的filter前面,并且要求可以拦截struts2匹配的请求-->
<!-- <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>*.action</url-pattern>
</filter-mapping> -->

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>


<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>sf2</param-value>
</init-param>
</filter>
<filter-mapping>
         <filter-name>openSessionInViewFilter</filter-name>
         <url-pattern>/*</url-pattern>
    </filter-mapping>
<filter>
   <filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
   <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
   <init-param>
      <param-name>entityManagerFactoryBeanName</param-name>   
      <param-value>entityManagerFactory1</param-value>     
   </init-param>  
</filter>
   
   
<error-page>
<exception-type>500</exception-type>
<location>/error/500.jsp</location>
</error-page>
<error-page>
   <error-code>404</error-code>
   <location>/error/404.jsp</location>
</error-page>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.spring-db.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:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xsi:schemaLocation="  
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
     ">
<context:annotation-config/>
  <!-- jndi数据源配制 -->
  <jee:jndi-lookup id="dataSource1" jndi-name="jdbc/data1"/>
  <jee:jndi-lookup id="dataSource2" jndi-name="jdbc/data2"/>
  

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
<property name="jtaTransactionManager">
   <ref bean="transactionManager" />
  </property>
</bean>


<bean id="sf2"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
    <prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
<property name="jtaTransactionManager">
   <ref bean="transactionManager" />
  </property>
</bean>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory1"  
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">  
        <property name="dataSource" ref="dataSource1" />
        <property name="persistenceUnitName" value="test" />
        <!-- <property name="persistenceXmlLocation" value="classpath:persistence.xml" />   -->
        <property name="jpaVendorAdapter">  
            <bean  
                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
                <property name="database" value="ORACLE" />  
                <property name="showSql" value="true" />  
                <!-- <property name="generateDdl" value="true" /> -->  
            </bean>  
        </property>
        
        <property name="jpaPropertyMap">  
            <map>  
                <entry key="hibernate.transaction.manager_lookup_class"  
                       value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />  
                <entry key="hibernate.transaction.flush_before_completion" value="true" />  
                <entry key="hibernate.transaction.auto_close_session" value="true" />  
                <entry key="hibernate.current_session_context_class" value="jta" />  
                <entry key="hibernate.connection.release_mode" value="auto" />  
            </map>  
        </property>   
    </bean>
   
     <bean id="entityManagerFactory2"  
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">  
        <property name="dataSource" ref="dataSource2" />
        <property name="persistenceUnitName" value="test" />
      <!--   <property name="persistenceXmlLocation" value="classpath:persistence.xml" />   -->
        <property name="jpaVendorAdapter">  
            <bean  
                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
                <property name="database" value="ORACLE" />  
                <property name="showSql" value="true" />  
               <!--  <property name="generateDdl" value="true" />   -->
            </bean>  
        </property>
        
        <property name="jpaPropertyMap">  
            <map>  
                <entry key="hibernate.transaction.manager_lookup_class"  
                       value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />  
                <entry key="hibernate.transaction.flush_before_completion" value="true" />  
                <entry key="hibernate.transaction.auto_close_session" value="true" />  
                <entry key="hibernate.current_session_context_class" value="jta" />  
                <entry key="hibernate.connection.release_mode" value="auto" />  
            </map>  
        </property>   
    </bean>

<!-- JTA事务管理器 -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager" >
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<tx:jta-transaction-manager  />
</beans>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-343777-1-1.html 上篇帖子: WebLogic服务器环境下打开附件(.rar/.zip/.doc/.xls)出错的解决方法 下篇帖子: 解决唯智项目发布weblogic中文显示和hql解析问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表