<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">題目如此啊,但不一定每個人的情況都會和我的一樣,感覺這是個非常蛋疼的問題,困擾了我好幾天。</span>
我在做一個SSH集成CXF用於實現web service的服務器框架。實際上是用spring+hibernate集成CXF,沒用到Struts。之前用過SSH,但沒有完整地自己搭建一次SSH框架,之前只是在別人搭好的框架上進行頁面開發。沒想到自己搭一次,各種問題。
我看了spring的事務管理的幾種方法,大概有五種,但是感覺不習慣第一種 每一個bean都有一個代理,和不習慣第五種 註解的方式,覺得麻煩。就不斷地在用二三四的方法嘗試,就分別是每一個bean共享一個代理、攔截器、和tx標籤配置的攔截器,三種方法不斷地嘗試,但都共有一個問題,spring的依賴注入失效。
開始的配置如下:
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="user" value="root" />
<property name="password" value="moment_root" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/moment" />
</bean>