Integrating Spring jpa into ninja

44 views
Skip to first unread message

lord Uhuru

unread,
Apr 1, 2017, 2:33:32 PM4/1/17
to ninja-framework
Hello, I'm a bit new to ninja.

But i think i got a pretty good handle of things now.

Coming from spring, I am used to Spring data jpa and I know how to use Dependency Injection with @Autowired.

Here in ninja, I am trying to use a spring data jpa jar I have created for data access. Simply put, the classes are interfaces,

that i wouldn't have to implement in order to use. Sth like 
public interface PortalUserRepository extends JpaRepository<PortalUser, Long> {

   
PortalUser getPortalUserByUsername(String username);

   
PortalUser getPortalUserByEmail(String email);

}

Injecting this to ninja with @Inject, it says no implementations found. This is where i inject

public class SetupDaoV2 {

   
@Inject
    PortalUserRepository portalUserRepository;

   
public void setup() {
       
try {
           
List<PortalUser> portalUsers = portalUserRepository.findAll();
           
if (portalUsers.size() == 0) {
               
// Create a new user and save it
                PortalUser portalUser = new PortalUser("King", "Bos", "Bos King",
                       
"gi...@gmail.com", "Passw00rd@",
                       
"gi...@gmail.com",
                       
new Timestamp(System.currentTimeMillis()), Boolean.TRUE,
                       
Boolean.TRUE, GenericStatusConstant.ACTIVE, Boolean.TRUE
                );
               
portalUserRepository.save(portalUser);
           
}
       
}catch (Exception ex){
            ex
.printStackTrace();
       
}
   
}
}

And the error
2017-04-01 19:06:55.262 [NinjaJetty] ERROR ninja.standalone.NinjaJetty.run(100) - Unable to start NinjaJetty
com.google.inject.CreationException: Unable to create injector, see the following errors:

1) No implementation for com.bw.dd.dsl.repository.PortalUserRepository was bound.
  while locating com.bw.dd.dsl.repository.PortalUserRepository
    for field at dao.SetupDaoV2.portalUserRepository(SetupDaoV2.java:18)
  while locating dao.SetupDaoV2
    for field at conf.StartUpActions.setupDao(StartUpActions.java:17)
  at conf.Module.configure(Module.java:14)

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470) ~[guice-4.1.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155) ~[guice-4.1.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107) ~[guice-4.1.0.jar:na]


Pls help.


Jonathan Lannoy

unread,
Apr 18, 2017, 9:21:39 AM4/18/17
to ninja-framework
Hi.

If I understand well, spring JPA is automatically creating concrete implmentation of PortalUserRepository?

They are probablye available only in a spring context and Google Guice doesn't see them. A solution could be to manage to access that spring context in your Guice module to bind the interface to the implementation you get from the Spring context. But an other question would be how do you make spring jpa aware of tje connection defined in ninja's application.conf?

I think you're trying to "twist" Ninja's stack in an never tried way... God luck.

Jonathan
Reply all
Reply to author
Forward
0 new messages