设置ear中war之间session共享

设置ear中war之间session共享

由J2EE Servlet规范中,可以知道,正常情况下war之间session是彼此独立的,不可以共享的。
但是现在大部分J2EE服务器,都实现了EAR中war之间的session共享,如weblogic(>=9)、websphere。

设置weblogic的EAR中war之间session共享有下面两种方法:

1:设置EAR中的weblogic-application.xml文件,加入如下片段:

    <wls:session-descriptor>
  <wls:persistent-store-type>memory</wls:persistent-store-type>
  <wls:sharing-enabled>true</wls:sharing-enabled>
 </wls:session-descriptor>
 
整个weblogic-application.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://www.bea.com/ns/weblogic/90" 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 http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    <wls:weblogic-version>10.0</wls:weblogic-version>
    <wls:context-root>testEARweb2</wls:context-root>
    <wls:session-descriptor>
  <wls:persistent-store-type>memory</wls:persistent-store-type>
  <wls:sharing-enabled>true</wls:sharing-enabled>
 </wls:session-descriptor>

</wls:weblogic-web-app>

2.设置需要共享session的war内的weblogic.xml文件,例如testEAR内有两个war,testEARweb1和testEARweb2,想让这两个war之间session共享,
则需要设置这两个war里面的weblogic.xml文件,同样,加入下面片段即可:
    <wls:session-descriptor>
  <wls:persistent-store-type>memory</wls:persistent-store-type>
  <wls:sharing-enabled>true</wls:sharing-enabled>
 </wls:session-descriptor>
设置后testEARweb1的weblogic.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://www.bea.com/ns/weblogic/90" 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 http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    <wls:weblogic-version>10.0</wls:weblogic-version>
    <wls:context-root>testEARweb1</wls:context-root>
    <wls:session-descriptor>
  <wls:persistent-store-type>memory</wls:persistent-store-type>
  <wls:sharing-enabled>true</wls:sharing-enabled>
 </wls:session-descriptor>

</wls:weblogic-web-app>
 
testEARweb2的weblogic.xml内容如下: 
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://www.bea.com/ns/weblogic/90" 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 http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    <wls:weblogic-version>10.0</wls:weblogic-version>
    <wls:context-root>testEARweb2</wls:context-root>
    <wls:session-descriptor>
  <wls:persistent-store-type>memory</wls:persistent-store-type>
  <wls:sharing-enabled>true</wls:sharing-enabled>
 </wls:session-descriptor>
</wls:weblogic-web-app>

这样,EAR内的war之间就可以共享session了。

对于WAS,需要设置ibm-application-ext.xmi文件,

<applicationext:ApplicationExtension xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:applicationext="applicationext.xmi" xmlns:application="application.xmi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:id="Application_ID_Ext" sharedSessionContext="true"> 

其中sharedSessionContext="true",就是说明要开启共享session。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值