繁体   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