user2424634
user2424634

Reputation:

How can I connect to MySQL database

I´m tryng to connect to MySQL Database with SpringBoot, but I got this error below:

Application failed to start with classpath: [file:/C:/Dev/Repositorios/jira-quality/target/classes/, file:/C:/Users/jboscod/.m2/repository/mysql/mysql-connector-java/8.0.21/mysql-connector-java-8.0.21.jar, file:/C:/Users/jboscod/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.1.9.RELEASE/spring-boot-starter-data-jpa-2.1.9.RELEASE.jar

Failed to load property source from location 'classpath:/application-desenv.yml'

My pom is this way:

<?xml version="1.0" encoding="UTF-8"?>
  <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>br.com.oss.jira.quality</groupId>
<artifactId>jira-quality</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jira-quality</name>
<description>Gerenciador de inconsistências no Jira</description>

<properties>
    <java.version>1.8</java.version>
    <lombok.version>1.18.6</lombok.version>
</properties>

<dependencies>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>12.2.0.1</version>
    </dependency> -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
    </dependency>  -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-quartz</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
               <!-- Exclude the default Jackson dependency -->
<!--            <exclusions> -->
<!--                <exclusion> -->
<!--                    <groupId>org.springframework.boot</groupId> -->
<!--                    <artifactId>spring-boot-starter-json</artifactId> -->
<!--                </exclusion> -->
<!--            </exclusions> -->
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>${gson.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.7.0</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<profiles>
    <profile>
        <id>desenv</id>
        <properties>
            <activatedProperties>desenv</activatedProperties>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <activatedProperties>prod</activatedProperties>
        </properties>
    </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

</project>

And my application.properties is below:

spring.jpa.hibernate.ddl-auto = none

spring.datasource.url = jdbc:mysql://localhost:3306/jiraquality

spring.datasource.username = root

spring.datasource.password = admin

spring.datasource.driver-class-name = com.mysql.jdbc.Driver

I don´t know if the problem is in my pom or my application file.

Upvotes: 0

Views: 918

Answers (2)

Kenyore
Kenyore

Reputation: 56

I noticed that Failed to load property source from location 'classpath:/application-desenv.yml'

Have you try to change your application.properties to application-desenv.yml?

Upvotes: 1

Imranmadbar
Imranmadbar

Reputation: 5460

If you don't add Spring Data JPA on you pom file add this:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>


  
    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <scope>runtime</scope>
    </dependency>
    

Clean your project and take Maven update. It will be working successfully.

Upvotes: 0

Related Questions