簡體   English   中英

讓Spring使用Play Framework 2.1(java)

[英]Getting Spring to work with Play Framework 2.1 (java)

我試圖讓Spring在我的Playframework 2.1項目中工作,但還沒有成功。 我正在關注如何讓它發揮作用的Guilliaume Bort教程 項目正確啟動,它調用動作(通過GET)signupForm罰款(如下所述),但當我嘗試提交表單時,我得到下一個異常:

得到了例外

它似乎不喜歡@Transactional注釋。 這是我的控制器代碼的一部分:

@org.springframework.stereotype.Controller
public class UserController extends Controller {
    @Autowired
    private UserService userService;

    public Result signupForm() {
        // This is the initial method called via GET (works fine)
    }

    @Transactional
    public Result signup() {
            ... code ....
            userService.save(user); // call to the injected service
            ... more code ...
        }
    }
    ... mode code ...

這是我的components.xml(放在/ conf中):

<?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">

    <context:component-scan base-package="controllers, services, dataaccess, models"/>
</beans>

(dataaccess是放置我的dao的地方)

這是我服務的一部分(以防萬一):

@Service("userService")
public class UserService {
    @Autowired
    private UserDao userDao;
    ... more code ...

最后,這是本案相關Dao的一部分:

@Repository("userDao")
public class UserDaoJpa implements UserDao {
    ... more code ...

正如您在下圖中看到的,Global中的getControllerInstance方法試圖獲取Transactional注釋的實例,我不知道為什么。 對我而言,它不應該試圖實例化它。 這不是彈簧自動掃描包裝中的事件。

這就是spring試圖實例化的東西

感謝您提供的任何幫助。

PS:我剛開始春天。

您可能導入了play.db.jpa.Transactional而不是org.springframework.transaction.annotation.Transactional

第一個在TransactionalAction包裝帶注釋的動作,其中Spring不知道,因此查找失敗。

您可能還希望將事務處理移至服務層。

只需將TransactionalAction類注冊到spring上下文

<bean class="play.db.jpa.TransactionalAction"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM