I am facing issue while connecting to MYSQL database.
Here is my application.properties
MySQL Database
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://dataurl.com:3306/
spring.datasource.username=usename
spring.datasource.password=paswd
It is working with different application but not this one. I excluded hsql in POM here is the snippet
<dependency>
>>><groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<exclusions>
<exclusion>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
But got this error: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public javax.sql.DataSource main.java.com.fileuploadutility.configurator.BatchConfiguration.dataSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] 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)} 2016-06-02 13:00:25.417 INFO 7776 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat 2016-06-02 13:00:25.426 WARN 7776 --- [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)
For trying differently I added
public class DataSourceConfiguration {
@Bean(name = "mysqlDS")
@ConfigurationProperties(prefix = "spring.mysql.ds")
public DataSource mysqlDS() {
return DataSourceBuilder.create().build();
}
and
@Autowired
@Qualifier("mysqlDS")
public DataSource dataSource;
But getting same the error