Main方法如下:
[code="java"]
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"ApplicationContext-jotm.xml"});
BeanFactory factory = (BeanFactory) context;
UserService userService = (UserService)factory.getBean("userService");
if(args[0].equals("help") || args[0].equals("?")){
System.out.println("-------------------------");
System.out.println("equip 设备同步");
System.out.println("-------------------------");
}
if(args[0].equals("equip")){
userService.synchronyEquipment();
}
}
[/code]
测试里面调用userService.synchronyEquipment(),可以正常终止。Main方法操作执行了,但程序不能终止。
我使用jotm操作两个数据库。我想是不是spring没有释放数据库连接?
不知道有人遇到过这种情况没有?
ApplicationContext-jotm.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm" />
</bean>
<bean id="eamds" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
<property name="dataSource">
<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
<property name="transactionManager" ref="jotm" />
<property name="driverName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/d7i" />
</bean>
</property>
<property name="user" value="root" />
<property name="password" value="root"/>
</bean>
<bean id="zhjds" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
<property name="dataSource">
<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
<property name="transactionManager" ref="jotm" />
<!-- property name="driverName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@10.10.150.216:1521:eampoc" /-->
<property name="driverName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/eampoc"/>
</bean>
</property>
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
<bean id="template1" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="eamds" />
</bean>
<bean id="template2" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="zhjds" />
</bean>
<bean id="EAMDao" class="com.hgsoft.EAMDAO">
<property name="jdbcTemplate">
<ref bean="template1"></ref>
</property>
<property name="fetchSize" value="1"/>
</bean>
<bean id="ZHJDao" class="com.hgsoft.ZHJDAO">
<property name="jdbcTemplate">
<ref bean="template2"></ref>
</property>
</bean>
<bean id="userService" class="com.hgsoft.UserServiceImpl">
<property name="EAMDao" ref="EAMDao"/>
<property name="executeService" ref="executeService"/>
<property name="yaml" ref="yaml"/>
<property name="yamlStr">
<value>equipment:
count: select count(*) from new_object_collection t where t.issended='0'
query: select t.equip_code,t.equip_name,t.sealflag from new_object_collection t where t.issended='0'
update: update new_object_collection set issended='1' where equip_code=?
insert: insert into eam_ncinv_equip (EQUIP_CODE,EQUIP_NAME,SEALFLAG ) values (?,?,?)</value>
</property>
</bean>
<bean id="yaml" class="org.yaml.snakeyaml.Yaml" scope="prototype" />
<bean id="executeServiceTarget" class="com.hgsoft.ExecuteService">
<property name="EAMDao" ref="EAMDao"/>
<property name="ZHJDao" ref="ZHJDao"/>
</bean>
<bean id="executeService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="txManager"/>
</property>
<property name="target">
<ref bean="executeServiceTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="executeSynchrony">PROPAGATION_REQUIRES_NEW,-Exception</prop>
</props>
</property>
</bean>
[/code]