Java 弹簧-连接未释放

Java 弹簧-连接未释放,java,spring,Java,Spring,我正在插入Oracle数据库,两个模式和两个表,我在Jboss 6.3.2中创建了两个XA数据源,具有相同的URL,但用户不同, 对于每个调用,我都会创建一个新的事务,经过一段时间后,我得到一个错误,即没有可用的连接。我猜连接没有被释放。我没有在春天的经验,所以如果我的实现是错误的,我需要一个建议 例外情况: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed conne

我正在插入Oracle数据库,两个模式和两个表,我在Jboss 6.3.2中创建了两个XA数据源,具有相同的URL,但用户不同, 对于每个调用,我都会创建一个新的事务,经过一段时间后,我得到一个错误,即没有可用的连接。我猜连接没有被释放。我没有在春天的经验,所以如果我的实现是错误的,我需要一个建议

例外情况:

java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/jdbc/tivibu_stb
            at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:151)
接口:

@RequestMapping  
@Transactional  
public interface RRStatisticsService {  

@Cache(CacheType.NO_CACHE)  
@AuthRequired(AuthType.USER)  
@Transactional(propagation = Propagation.REQUIRES_NEW)  
@RequestMapping(value = "/private/rr/sendChannelEvents.ajax", method = RequestMethod.POST)  
public @ResponseBody void sendChannelEvents(@Valid @RequestBody ChannelRatingEvents events,  
        @SubscriberId String subscriberId, @UserId String userId, @DeviceId String deviceId) throws PortalException;  

@Cache(CacheType.NO_CACHE)  
@AuthRequired(AuthType.USER)  
@Transactional(propagation = Propagation.REQUIRES_NEW)  
@RequestMapping(value = "/private/rr/sendVodEvents.ajax", method = RequestMethod.POST)  
public @ResponseBody void sendVodEvents(@Valid @RequestBody VodRatingEvents events,  
        @SubscriberId String subscriberId, @UserId String userId, @DeviceId String deviceId) throws PortalException;  
}  
豆子:

stbportal-servlet.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans       
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- Component auto-scanning -->
<context:component-scan base-package="com.ericsson.iptv.portal.avalanche.tt.rr.iap" />

数据源定义:

<xa-datasource jndi-name="java:/jdbc/tivibu_stb" pool-name="jdbc_tivibu_stb" enabled="true" use-ccm="false">  
                    <xa-datasource-property name="User">  
                        USER2  
                    </xa-datasource-property>  
                    <xa-datasource-property name="Password">  
                        PWD2  
                    </xa-datasource-property>  
                    <xa-datasource-property name="URL">  
                        jdbc:oracle:thin:@hostip2:1521:TTEST2  
                    </xa-datasource-property>  
                    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>  
                    <driver>ojdbc</driver>  
                    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>  
                    <xa-pool>  
                        <min-pool-size>1</min-pool-size>  
                        <max-pool-size>5</max-pool-size>  
                        <use-strict-min>false</use-strict-min>  
                        <is-same-rm-override>false</is-same-rm-override>  
                        <interleaving>false</interleaving>  
                        <no-tx-separate-pools>true</no-tx-separate-pools>  
                        <pad-xid>false</pad-xid>  
                        <wrap-xa-resource>false</wrap-xa-resource>  
                    </xa-pool>  
                    <validation>  
                        <validate-on-match>false</validate-on-match>  
                        <background-validation>false</background-validation>  
                    </validation>  
                    <timeout>  
                        <set-tx-query-timeout>false</set-tx-query-timeout>  
                        <blocking-timeout-millis>0</blocking-timeout-millis>  
                        <idle-timeout-minutes>1</idle-timeout-minutes>  
                        <query-timeout>0</query-timeout>  
                        <use-try-lock>0</use-try-lock>  
                        <allocation-retry>0</allocation-retry>  
                        <allocation-retry-wait-millis>0</allocation-retry-wait-millis>  
                        <xa-resource-timeout>0</xa-resource-timeout>  
                    </timeout>  
                    <statement>  
                        <share-prepared-statements>false</share-prepared-statements>  
                    </statement>  
                </xa-datasource>  

用户2
PWD2
jdbc:oracle:thin:@hostip2:1521:TTEST2
oracle.jdbc.xa.client.oraclexadasource
ojdbc
事务读取已提交
1.
5.
假的
假的
假的
真的
假的
假的
假的
假的
假的
0
1.
0
0
0
0
0
假的

在代码(业务逻辑)完成运行后,是否关闭应用程序内容。((FileSystemXmlApplicationContext)上下文)。关闭();((ClassPathXmlApplicationContext)上下文).close();--->这是适用的。@KalyanChavali你到底为什么要他关闭上下文。。。这将基本上破坏应用程序。您不必关闭它,也不必自己构建它(在启动期间只需一次)。我看到了一个
@Transactional
,但是如果没有它,
@Transactional
几乎什么也做不了。另外,您不应该在每次需要时创建
JdbcTemplate
,只需创建一次即可重用。在应用程序上下文中执行jndi查找,并在那里构造一个
JdbcTemplate
,然后简单地将其注入。我以这种方式创建jdbc模板,因为我在应用程序属性中存储了jndi查找名称。我会试试你的建议。谢谢
<xa-datasource jndi-name="java:/jdbc/tivibu_stb" pool-name="jdbc_tivibu_stb" enabled="true" use-ccm="false">  
                    <xa-datasource-property name="User">  
                        USER2  
                    </xa-datasource-property>  
                    <xa-datasource-property name="Password">  
                        PWD2  
                    </xa-datasource-property>  
                    <xa-datasource-property name="URL">  
                        jdbc:oracle:thin:@hostip2:1521:TTEST2  
                    </xa-datasource-property>  
                    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>  
                    <driver>ojdbc</driver>  
                    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>  
                    <xa-pool>  
                        <min-pool-size>1</min-pool-size>  
                        <max-pool-size>5</max-pool-size>  
                        <use-strict-min>false</use-strict-min>  
                        <is-same-rm-override>false</is-same-rm-override>  
                        <interleaving>false</interleaving>  
                        <no-tx-separate-pools>true</no-tx-separate-pools>  
                        <pad-xid>false</pad-xid>  
                        <wrap-xa-resource>false</wrap-xa-resource>  
                    </xa-pool>  
                    <validation>  
                        <validate-on-match>false</validate-on-match>  
                        <background-validation>false</background-validation>  
                    </validation>  
                    <timeout>  
                        <set-tx-query-timeout>false</set-tx-query-timeout>  
                        <blocking-timeout-millis>0</blocking-timeout-millis>  
                        <idle-timeout-minutes>1</idle-timeout-minutes>  
                        <query-timeout>0</query-timeout>  
                        <use-try-lock>0</use-try-lock>  
                        <allocation-retry>0</allocation-retry>  
                        <allocation-retry-wait-millis>0</allocation-retry-wait-millis>  
                        <xa-resource-timeout>0</xa-resource-timeout>  
                    </timeout>  
                    <statement>  
                        <share-prepared-statements>false</share-prepared-statements>  
                    </statement>  
                </xa-datasource>