我正在使用JavaFX的Spring 3.2.4並希望實現一種方法,其中操作將在事務中執行。我在控制器代碼如下所示:春季交易註釋不起作用
@Transactional(rollbackFor = { ServiceException.class,
ValidationException.class })
public void registerVolunteer(User user, Volunteer volunteer)
throws ServiceException, ValidationException {
User ret = userService.create(user);
volunteer.setUser(ret);
volunteerService.untransactedCreate(volunteer);
}
我的應用上下文:
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<!-- Transaction Manager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
試圖運行它,我得到這個錯誤信息:
Controller method "onBackClicked" not found.
/home/workspace/project/NewProject/target/classes/fxml/RegisterVolunteer.fxml:69
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:497)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:594)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2472)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2177)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:97)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:81)
at org.impactvolunteers.management.gui.Screen.init(Screen.java:50)
at org.impactvolunteers.management.gui.ScreensController.init(ScreensController.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
...
的方法存在。通過刪除註釋或將方法從public
更改爲private
或從配置中刪除bean,程序將運行,但@Transactional
-annotation根本不起作用。刪除proxy-target-class="true"
導致我另一個錯誤。
您的錯誤消息與交易註釋無關。你可能會注意到你的棧跟蹤中根本沒有引用Spring應用程序上下文。只有當您的服務沒有實現接口時,才需要使用CGLIB代理目標類。您的例外是說JavaFX找不到控制器方法。那個控制器用'@ Controller'註釋,並且你的Spring XML中是否有'? –
JamesENL
我將該方法移至單獨的服務類,並解決了此問題。我沒有這兩個,因爲我正在開發一個使用JavaFX的本機應用程序,而我沒有使用MVC。錯誤消息與註釋無關,但將方法從公共更改爲私有刪除了錯誤消息,這對我來說顯得很奇怪,但我並不十分了解Spring的具體情況,所以... –