My Spring boot app is failing to start with the following message in the console.
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2018-03-27 13:42:13.816 INFO 2516 --- [ main] com.bijit.BootTestApplication : Starting BootTestApplication on INENBIRINBL2C with PID 2516 (started by birinb in C:\Users\birinb\workspace\Spring Projects1\BootTest)
2018-03-27 13:42:13.818 INFO 2516 --- [ main] com.bijit.BootTestApplication : No active profile set, falling back to default profiles: default
2018-03-27 13:42:13.851 INFO 2516 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@184cf7cf: startup date [Tue Mar 27 13:42:13 IST 2018]; root of context hierarchy
2018-03-27 13:42:14.508 INFO 2516 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-03-27 13:42:14.524 INFO 2516 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-03-27 13:42:14.525 INFO 2516 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-03-27 13:42:14.529 INFO 2516 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_131\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_131/bin/server;C:/Program Files/Java/jre1.8.0_131/bin;C:/Program Files/Java/jre1.8.0_131/lib/amd64;C:\Program Files\avs\bin;C:\Program Files (x86)\RSA SecurID Token Common;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\EMC\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Java\jdk1.8.0_121\bin;C:\Users\birinb\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\Users\birinb\AppData\Local\atom\bin;C:\Users\birinb\Software\eclipse;;.]
2018-03-27 13:42:14.617 INFO 2516 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-03-27 13:42:14.617 INFO 2516 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 768 ms
2018-03-27 13:42:14.656 INFO 2516 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-27 13:42:14.690 WARN 2516 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerServiceImpl': Unsatisfied dependency expressed through field 'dao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerDaoImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' available
2018-03-27 13:42:14.692 INFO 2516 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-03-27 13:42:14.699 WARN 2516 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2018-03-27 13:42:14.705 INFO 2516 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-03-27 13:42:14.797 ERROR 2516 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field dao in com.bijit.service.CustomerServiceImpl required a bean of type 'javax.persistence.EntityManagerFactory' that could not be found.
Action:
Consider defining a bean of type 'javax.persistence.EntityManagerFactory' in your configuration.
-Saying entity manager bean not found in DaoImpl class, but I have defined it there.
package com.bijit.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.bijit.entity.Customer;
@Repository
@Transactional
public class CustomerDaoImpl implements CustomerDao {
@PersistenceContext
EntityManager em;
public List<Customer> findAll(){
TypedQuery<Customer> query =em.createQuery("Select c from customer c", Customer.class);
return query.getResultList();
}
public Customer findById(Long id){
return em.find(Customer.class, id);
}
public void deleteCustomer(Customer customer){
em.remove(customer);
}
public void deleteById(Long id){
Customer customer = findById(id);
em.remove(customer);
}
public void saveCustomer(Customer customer){
if(customer.getId()==null){
em.persist(customer);
}
else{
em.merge(customer);
}
}
}
Please help me out. Can't understand what the issue is. Tried using @Autowired also in place of @PersistanceContext still it's not working.