Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Spring to work with Play Framework 2.1 (java)

I'm trying to get Spring working in my Playframework 2.1 project but with no success yet. I'm following Guilliaume Bort's tutorial on how to get it to work. The project starts correctly, it calls the action (via GET) signupForm fine(described below) but when I try to submit the form, I get the next Exception:

Exception gotten

It seems to not like the @Transactional annotation. This is part my controller code:

@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 ...

This is my components.xml (placed in /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 is where my dao's are placed)

This is part of my service (just in case it is necessary):

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

And finally this is part of the relevant Dao for this case:

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

As you can see in the image below, the getControllerInstance method in Global is trying to get an instance of the Transactional annotation and I don't know why. To me, it shouldn't be trying to instantiate it. It isn't event in the auto scanned packages by spring.

This is what spring tries to instantiate

Thank you for any help you could provide.

PS: I'm new to spring.

like image 938
Franco Avatar asked Jul 12 '26 19:07

Franco


1 Answers

You probably imported play.db.jpa.Transactional instead of org.springframework.transaction.annotation.Transactional.

The first one wraps the annotated action in TransactionalAction, of which Spring has no idea and hence the lookup fails.

You probably also want to move transaction handling to your service layer.

like image 57
soulcheck Avatar answered Jul 14 '26 08:07

soulcheck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!