0
votes

I had already declared my driver in my jpa class and also the dependecy for the connector for mysql and have the define schema in my DB. but when am crating the war then message showing in logs the driver is loaded but when am class the api it is showing no suitable driver is find for {MySql}

Root WebApplicationContext: initialization started Refreshing Root WebApplicationContext: startup date [Mon Sep 02 10:58:58 IST 2019]; root of context hierarchy Registering annotated classes: [class com.ghumapp.config.ApplicationConfig] JSR-330 'javax.inject.Inject' annotation found and supported for autowiring Bean 'applicationConfig' of type [class com.ghumapp.config.ApplicationConfig$$EnhancerBySpringCGLIB$$c8072be1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) Loaded JDBC driver: com.mysql.cj.jdbc.Driver Building JPA container EntityManagerFactory for persistence unit 'default' Initialized JPA EntityManagerFactory for persistence unit 'default' Mapped "{[/getCity],methods=[GET]}" onto public java.util.List com.ghumapp.services.CityServices.saveCityData() Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Mon Sep 02 10:58:58 IST 2019]; root of context hierarchy Root WebApplicationContext: initialization completed in 1330 ms FrameworkServlet 'dispatcher': initialization started Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Sep 02 10:58:59 IST 2019]; parent: Root WebApplicationContext Registering annotated classes: [class com.ghumapp.config.WebConfig] JSR-330 'javax.inject.Inject' annotation found and supported for autowiring Mapped "{[/getCity],methods=[GET]}" onto public java.util.List com.ghumapp.services.CityServices.saveCityData() Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Sep 02 10:58:59 IST 2019]; parent: Root WebApplicationContext FrameworkServlet 'dispatcher': initialization completed in 124 ms 02-Sep-2019 10:59:00.017 INFO [http-nio-8080-exec-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/home/yash/Downloads/apache-tomcat-9.0.22/webapps/ghumapp.war] has finished in [2,219] ms Hibernate: select cities0_.id as id1_0_0_, cities0_. name as column2_0_0_, cities0_.Dist as Dist3_0_0_, cities0_.population as populati4_0_0_ from cities cities0_ where cities0_.id=? No suitable driver found for {mysql.url}

logs whic is comming in my apache server

@Value("${mysql.user}")
private String dbUserName;

@Value("${mysql.password}")
private String dbPassword;

@Value("${mysql.url}")
private String mysqlUrl;


public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(new String[] { "com.app" });

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    em.setJpaProperties(additionalProperties());
    return em;
}

@Bean
public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
    dataSource.setUrl(mysqlUrl);
    dataSource.setUsername(dbUserName);
    dataSource.setPassword(dbPassword);
    return dataSource;
}
1
You are using a placeholder and nothing is resolving the placeholders.M. Deinum
am not understand what you said. can you plz suggest me a better solution for this erroryash
You probably have @Value(${mysql.url} on your mysqlUrl` field and apparently there is nothing replacing the @Value hence you don't have a placeholder configured in your application.M. Deinum
@Value("{mysql.user}") private String dbUserName; @Value("{mysql.password}") private String dbPassword; @Value("{mysql.url}") private String mysqlUrl;yash
They should have a leading $ to be processed by Spring (as mentioned in the answer, below).M. Deinum

1 Answers

0
votes

It seems mysqlUrl value is not correct and it's value does not loaded from properties file. For example, this:

@Value("{mysql.url}")
private String mysqlUrl;

should be changed to this (consider $):

@Value("${mysql.url}")
private String mysqlUrl;