0
votes

I use Play Framework + Spring Data JPA from this example:

https://github.com/typesafehub/play-spring-data-jpa

I have models, repositories and now I want to initialize my DB on start up. I inject repositories to my Global.java file using @Autowired, but they equals to null on run time. It's because Spring don't try to inject dependencies to Global.java, because Global.java don't have even package name, so I can't tell Spring to scan his package!

With controllers Spring DI works well, but how to use it in Global.java? How to initialize database using repositories?

2

2 Answers

2
votes

You can change package of Global.java in application.conf by setting property application.global.

Other way can be to fetch dependency explicitly calling

context.getBean(YourBeanClass)

in Global.java instead of autowiring it, as you have context available in Global.

0
votes

You may explicitly create a bean by defining it in your context xml <bean id="global" class="Global"></bean>

Also, having classes in default packages is not a good idea.