-3

here is my Repository

@Service
public class FuneralPricingRepository {

    @PersistenceContext
    private EntityManager em;  //this is null

    public List<FuneralPricing> findAll() {
        return this.em.createNativeQuery("SELECT * FROM FUNERALPRICING").getResultList();
    }
}

AS400calls is autowired but funeralPricingRepository is not.

public class TestFuneralPremiumProvider implements TestHandler {

    @Autowired
    private As400Calls as400Calls; //this is not null

    @Autowired
    private FuneralPricingRepository funeralPricingRepository; //this is null

Please help...

Michael
  • 57,169
  • 9
  • 80
  • 125
DIMAKATSO BOPAPE
  • 153
  • 1
  • 2
  • 11
  • Check is package of `FuneralPricingRepository` is in `componentscan` path? – Javasick Oct 31 '16 at 07:17
  • `@Autowired` cannot be `null`. If a dependency cannot be resolved your application will blow up. If that isn't the case you are not using auto wiring or are constructing an instance of `TestFuneralPremiumProvider` yourself. – M. Deinum Oct 31 '16 at 08:00

2 Answers2

0

You're not allowed to inject EntityManager this way. Inject EntityManagerFactory instead. Then both injections should work.

An entity manager can only be injected in classes running inside a transaction. In other words, it can only be injected in a EJB. Other classe must use an EntityManagerFactory to create and destroy an EntityManager.

-Source

Is your Repository in a package in componentscan path? If not yet, add

@ComponentScan("com.my.package.where.repository.is")

Another thing is your repository. What is the reason not to use Spring Data JPA? Simply extend CRUDRepository and you'll receive findAll and some more methods for free.

Community
  • 1
  • 1
xenteros
  • 15,586
  • 12
  • 56
  • 91
0

I think problem in this

TestFuneralPremiumProvider 

without annotation @Component or declaration bean in config