this is my first interface service class having two methods
package services;//this is my service interface class
import com.google.inject.ImplementedBy;
import dtos.MainDTO;
@ImplementedBy(UserServiceImpl.class)
public interface UserService {
MainDTO getUserDetaile(Integer userId);
MainDTO getAllUserDetails();
}
this is my second interface service class having two DAO query methods
package services;//this is my DAO interface class
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
public interface UserRepository extends CrudRepository<Users, Long> {
@Query("select userId,firstName from Users where userId =:userId")
public List<Object[]> getUserDetails(@Param("userId") Integer userId);
@Query("select userId,firstName from Users")
public List<Object[]> getAllUserDetails();
}
And this is the class implementation class for above two interfaces.
In 1st interface i annotated with @Implementedby annotation and its working fine. But for 2nd interface what needs to be added?
package services;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
import org.springframework.stereotype.Service;
import dtos.MainDTO;
import dtos.UserDTO;
@Service
public class UserServiceImpl implements UserService {
private UserRepository userRepository;
@Inject
public UserServiceImpl(UserRepository userRepository){
this.userRepository = userRepository;
}
@Override
public MainDTO getUserDetaile(Integer userId){
//method implementaion goes here
}
@Override
public MainDTO getAllUserDetails() {
//method implementaion goes here
}
Facing a problem like

First, you need to have guice-repository library added here it is.
In your module, you need to install repositories like the following
@Override
protected void configure() {
//Repository classes auto-scanned by package name
install(new ScanningJpaRepositoryModule(repositoriesBasePackageName, persistenceUnitName));
}
Once you have the repos scanned, you can inject your interfaces directly into your service or where you want.
Full details can be found here.
The valid constructor for a Play module will be like the following.
public YourModule(Environment environment, Configuration configuration) {
this.environment = environment;
this.configuration = configuration;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With