java.lang.IllegalArgumentException: DataSource must not be null

tip

If you're unit testing, you should instantiate only the service and mock the dependencies. If you're testing integration, you should add all the mocking to the configurations file.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • DataSource must not be null
    via by Unknown author,
  • Spring Boot test class wont inject beans
    via Stack Overflow by rayman
    ,
    • java.lang.IllegalArgumentException: DataSource must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.jdbc.datasource.lookup.SingleDataSourceLookup.<init>(SingleDataSourceLookup.java:40) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.setDataSource(LocalContainerEntityManagerFactoryBean.java:238) at com.myc.cc.repository.PersistenceJPAConfig.entityManagerFactory(PersistenceJPAConfig.java:43) at com.myc.cc.repository.PersistenceJPAConfig.entityManager(PersistenceJPAConfig.java:37) at com.myc.cc.repository.SearchPersonPredicates.findIdByEM(SearchPersonPredicates.java:121) at com.myc.cc.service.impl.SearchPersonServiceImpl.findPnumberbyEM(SearchPersonServiceImpl.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201) at com.sun.proxy.$Proxy114.findPnumberbyEM(Unknown Source) at com.myc.cc.web.SearchPersonController.searchPerson(SearchPersonController.java:109) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606)

    Users with the same issue

    osvzs
    osvzs2 times, last one,
    odd
    odd2 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    mauritius
    mauritius1 times, last one,
    189 more bugmates