I'm trying to develop a multi-module spring boot project with multi-datasource connection. I have separate this project in 5 modules:
-springboot-multiple-maven-modules:
1. domain -> database2's model
2. domain2 -> database2's model
3. persistence -> database1's persistence
4. persistence2 -> database2's persistence
5. web -> Access to database1 and database2
You can download the code in the following link:
GitHub Project
I've configure both datasource in this way:
- database1:
package rc.persistence;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(entityManagerFactoryRef = "hotelEntityManagerFactory", transactionManagerRef = "hotelTransactionManager", basePackages = {
"rc.repository" }) //Mirar si se puede sustituir por rc.domain o rc.repository
public class HotelDbConfig {
#Autowired
private Environment env;
#Bean(name = "hotelDataSource")
#ConfigurationProperties(prefix = "hoteles.datasource")
public DataSource customDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("hoteles.datasource.driver-class-name"));
dataSource.setUrl(env.getProperty("hoteles.datasource.url"));
dataSource.setUsername(env.getProperty("hoteles.datasource.username"));
dataSource.setPassword(env.getProperty("hoteles.datasource.password"));
return dataSource;
}
#Bean(name = "hotelEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
#Qualifier("hotelDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("rc.domain")
.persistenceUnit("hotel").build();
}
#Bean(name = "hotelTransactionManager")
public PlatformTransactionManager transactionManager(
#Qualifier("hotelEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
database2:
package rc.persistence2;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(entityManagerFactoryRef = "cocheEntityManagerFactory", transactionManagerRef = "cocheTransactionManager", basePackages = {
"rc.repository2" })
public class CocheDbConfig {
#Autowired
private Environment env;
#Primary
#Bean(name = "cocheDataSource")
#ConfigurationProperties(prefix = "coches.datasource")
public DataSource customDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("coches.datasource.driver-class-name"));
dataSource.setUrl(env.getProperty("coches.datasource.url"));
dataSource.setUsername(env.getProperty("coches.datasource.username"));
dataSource.setPassword(env.getProperty("coches.datasource.password"));
return dataSource;
}
#Primary
#Bean(name = "cocheEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
#Qualifier("cocheDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("rc.domain2")
.persistenceUnit("coche").build();
}
#Primary
#Bean(name = "cocheTransactionManager")
public PlatformTransactionManager transactionManager(
#Qualifier("cocheEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
But when I try to use repositories from web module:
package rc.web;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import rc.domain2.Coche;
import rc.persistence2.CocheRepository;
#RestController
public class CocheController {
#Autowired
private CocheRepository cocheRepository;
public CocheController(CocheRepository cocheRepository) {
this.cocheRepository = cocheRepository;
}
#GetMapping(value = "/coches")
public List<Coche> getCoches() {
List<Coche> hotels = this.cocheRepository.findAll();
return hotels;
}
}
It shows me the following error:
I've tried differents possibilities but always the same result:
2018-09-27 17:08:58.399 WARN 15272 --- [ main]
ConfigServletWebServerApplicationContext : Exception encountered
during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'cocheController' defined in file
[C:\springboot-multiple-maven-modules\web\target\classes\rc\web\CocheController.class]:
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type 'rc.persistence2.CocheRepository' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {} 2018-09-27 17:08:58.399 INFO 15272 --- [
main] j.LocalContainerEntityManagerFactoryBean : Closing JPA
EntityManagerFactory for persistence unit 'coche' 2018-09-27
17:08:58.400 INFO 15272 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Closing JPA
EntityManagerFactory for persistence unit 'hotel' 2018-09-27
17:08:58.403 INFO 15272 --- [ main]
o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-09-27 17:08:58.421 INFO 15272 --- [ main]
ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report
re-run your application with 'debug' enabled. 2018-09-27 17:08:58.670
ERROR 15272 --- [ main]
o.s.b.d.LoggingFailureAnalysisReporter :
*************************** APPLICATION FAILED TO START
Description:
Parameter 0 of constructor in rc.web.CocheController required a bean
of type 'rc.persistence2.CocheRepository' that could not be found.
Action:
Consider defining a bean of type 'rc.persistence2.CocheRepository' in
your configuration.
Please help!!
Thanks in advance!
You got a error in the datasource configuration. Your CocheDbConfig datasource is scanning in the based packages "rc.repository2" to find out Repository class so it can't find the bean 'rc.persistence2.CocheRepository' in your controller.
You should change the based packages in your database2 datasource like this
#EnableJpaRepositories(entityManagerFactoryRef = "cocheEntityManagerFactory", transactionManagerRef = "cocheTransactionManager", basePackages = {
"rc.persistence2" })
Related
I got this error "access denied for user using password=NO" where I already added the right password.please give me solution on this.
Here is the stack trace:
java.sql.SQLException: Access denied for user 'www.abcom.in'#'localhost' (using password: NO)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql- connector-java-8.0.26.jar:8.0.26]
at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122 ) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[na:1.8.0_292]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[na:1.8.0_292]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:155) ~[spring-jdbc-5.3.9.jar:5.3.9]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:146) ~[spring-jdbc-5.3.9.jar:5.3.9]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205) ~[spring-jdbc-5.3.9.jar:5.3.9]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) ~[spring-jdbc-5.3.9.jar:5.3.9]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-
Application configuration file Program:
package com.training.newspringquerydsl.config;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import com.querydsl.jpa.impl.JPAQueryFactory;
#Configuration
#ComponentScan(basePackages = "com")
public class AppConfiguration {
#Bean("datasource")
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername(dataSource.getUsername());
dataSource.setPassword(dataSource.getPassword());
dataSource.setUrl("jdbc:mysql://localhost/springwebservices");
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
return dataSource;
}
#Bean
public JPAQueryFactory getjpaQueryFactory() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(null);
EntityManager em = emf.createEntityManager();
JPAQueryFactory queryFactory = new JPAQueryFactory(em);
return queryFactory;
}
}
Application properties file:
spring.datasource.url=jdbc:mysql://localhost:3306/springwebservices
spring.datasource.Data-username=root
spring.datasource.Data-password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
The properties with username and password are wrong:
It must be:
spring.datasource.username=root
spring.datasource.password=root
I am getting this following exception on my production while running my code. I don't know what I am making mistake, the same code is happily running on my local machine, please help
Feb 19 13:46:40 ip-10-0-77-139 server: ShopifyGetItems: Service
function shop.getShopifyDomain():
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateConfig': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'environment' available
import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
#Configuration
#EnableTransactionManagement
#ComponentScan({ "com.webbee.app" })
#PropertySource(value = { "classpath:internal.properties" })
public class HibernateConfig {
#Autowired
private Environment environment;
private Properties hibernateProperties() {
System.out.println(environment.getRequiredProperty("hibernate.dialect"));
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.jdbc.batch_size", 1000); // batch size for save or update
return properties;
}
}
It will be good, if you can debug the issue -
System.out.println("Created beans: " + Arrays.toString(context.getBeanNamesForType(Environment.class)));
if you are getting empty list it means, your bean is not instantiated in spring container and there is some problem with component scan.
This helped me in spring boot 2.4 but not in 2.6
spring:
config:
use-legacy-processing: false
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-04-12 18:47:51.811 ERROR 340 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field leadRepository in com.example.lead.controller.LeadController required a bean of type 'com.example.lead.repo.LeadRepository' that could not be found.
Action:
Consider defining a bean of type 'com.example.lead.repo.LeadRepository' in your configuration.
package com.example.lead.repo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.leadmodel.Lead;
import com.example.leadmodel.LeadEntity;
#Repository
public interface LeadRepository extends JpaRepository<Lead, Integer> {
#Bean
#Autowired
Lead findOne(Integer lead_id);
void save(LeadEntity leadEntity);
}
I am working with Spring and Spring Data JPA. When deploying my application in Tomcat I'm getting the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'myController': Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire field:
private com.service.MyService com.controller.MyController.myService; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'MyService': Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire field:
private com.repository.MyRepository com.service.MyService.myRepository; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
[com.repository.MyRepository] found for dependency: expected at least 1 bean which qualifies
as autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
The following are my code:
MyController.java
package com.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.domain.MyEntity;
import com.service.MyService;
#RestController
#RequestMapping(MyController.ROOT_RESOURCE_PATH)
public class MyController{
public static final String ROOT_RESOURCE_PATH = "/test";
#Autowired
private MyService myService;
#RequestMapping(value="/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<MyEntity> getAll() {
return myService.getAll();
}
}
MyService.java
package com.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.domain.MyEntity;
import com.repository.MyRepository;
#Service(value = "MyService")
public class MyService {
#Autowired
private MyRepository myRepository;
public List<MyEntity> getAll() {
return myRepository.findAll();
}
}
MyRepository.java
package com.repository;
import java.util.List;
import org.springframework.data.repository.Repository;
import com.domain.MyEntity;
public interface MyRepository extends Repository<MyEntity, Long> {
public List<MyEntity> findAll();
}
}
MyApplication-context.xml
<jpa:repositories base-package="com.repository" />
<context:component-scan base-package="com.service" />
<context:component-scan base-package="com.controller" />
<context:annotation-config />
I'm not seeing your repository annotated. That might be the reason why Spring couldn't create a bean for MyRepository during component scan. Annotate it with #Repository
i am using Spring’s WebApplicationInitializer interface to create the application context programmatically and using hibernate with jpa specification for data persistence. i put db.properties file in src folder adding #PropertySource("classpath:db.properties") in WebAppConfig class. i have following jars for hibernate in classpath.............
antlr-2.7.7.jar aopalliance-1.0.jar
commons-dbcp-1.4-javadoc.jar
commons-dbcp-1.4-sources.jar
commons-dbcp-1.4.jar
commons-logging-1.1.1.jar
commons-pool-1.6-javadoc.jar
commons-pool-1.6-sources.jar
commons-pool-1.6.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.9.Final.jar
hibernate-entitymanager-4.1.9.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.17.1-GA.jar
jboss-logging-3.1.0.GA.jar
jta-1.1.jar
mysql-connector-java-5.1.6-bin.jar
web initialzer class code
package com.genesis.init;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class Initializer implements WebApplicationInitializer {
// gets invoked automatically when application starts up
public void onStartup(ServletContext servletContext)
throws ServletException {
// Create ApplicationContext. I'm using the
// AnnotationConfigWebApplicationContext to avoid using beans xml files.
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebAppConfig.class);
// Add the servlet mapping manually and make it initialize automatically
Dynamic servlet = servletContext.addServlet("dispatcher",
new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
}
}
WebAppConfig code
package com.genesis.init;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#Configuration
// specifies this class as configuration
#ComponentScan("com.genesis")
// specifies which package to scan
#EnableWebMvc
// enable spring web mvc to use annotation
#PropertySource("classpath:db.properties")
// plugs in property file which located in the resource folder.
#EnableTransactionManagement
// enables Spring’s annotation-driven transaction management capability.
public class WebAppConfig extends WebMvcConfigurerAdapter {
#Autowired
private Environment env;
// Tell SpingMVC where to find view scripts
#Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
// Enable serving static resources even when DispatcherServlet is mapped to
#Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
// Enable accessing entityManager from view scripts. Required when using
// lazy loading
#Override
public void addInterceptors(InterceptorRegistry registry) {
OpenEntityManagerInViewInterceptor viewInterceptor = new OpenEntityManagerInViewInterceptor();
viewInterceptor.setEntityManagerFactory(entityManagerFactory().getObject());
registry.addWebRequestInterceptor(viewInterceptor);
}
//Set up dataSource to be used by Hibernate. Also make sure the connection doesn't go down
#Bean
public DataSource getDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(env.getProperty("url"));
dataSource.setDriverClassName(env.getProperty("driver"));
dataSource.setUsername(env.getProperty("user"));
dataSource.setPassword(env.getProperty("pass"));
dataSource.setValidationQueryTimeout(5);
return dataSource;
}
//Set up JPA and transactionManager
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(getDataSource());
emf.setPackagesToScan("com.genesis.model");
// let Hibernate know which database we're using.
// note that this is vendor specific, not JPA
Map<String, Object> opts = emf.getJpaPropertyMap();
opts.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
HibernateJpaVendorAdapter va = new HibernateJpaVendorAdapter();
emf.setJpaVendorAdapter(va);
return emf;
}
//Let us use PlatformTransactionManager directly to implement programmatic approach to implement transactions
//To start a new transaction you need to have a instance of TransactionDefinition
#Bean
public PlatformTransactionManager transactionManager(){
JpaTransactionManager transactionManager=new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager();
}
}
database property file is as.
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
hibernate.dialect=org.hibernate.dialect.MySQLDialect
user=root
pass=iems1234
show_sql=true
packages.to.scan=com.genesis.model
console output is...........
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class com.genesis.init.WebAppConfig: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1507)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1145)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:493)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:512)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1267)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1084)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3920)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:293)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1503)
... 27 more
Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQLDialect
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:76)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:170)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 33 more
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.MySQLDialect ]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)
... 44 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.MySQLDialect
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
... 45 more
You aren't using Maven or Gradle as a build tool, so you will have to make sure that all of your needed jar files are in the WEB-INF/lib directory of your web application. If it isn't in that directory it isn't on the classpath.
I strongly suggest using one of the earlier mentioned build tools to build your artifact and manage your dependencies. It will save you a lot of searching and headaches.
Links
Maven
Gradle