I am setting up a Springboot(version 2.0.4) project with maven build to use PostgreSQL database. I want to utilize data-source auto configuration feature of Springboot but it is giving me following errors:
Field dataSource in com.praveen.demo.MyController required a bean of type 'javax.sql.DataSource' that could not be found.
Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required classes 'javax.transaction.TransactionManager', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
In my pom.xml I've dependencies on postgresql and HikariCP as below:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
Also I've in my application.properties file
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb?user=myself&password=mypassword
In my Java file having #RestController annotation , I am injecting DataSource as below:
#Autowired
private DataSource dataSource;
I am following below artcile: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html
I do not want to use JPA. I believe article is not suggesting to use the JPA for auto configuration to work.
I am expecting that Spring boot should auto-configure Data source for the application as I've declared the dependencies and provided the database URL. Still I get errors(as mentioned on top) on starting the application.
Edit-1: I am following below article:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html
Edit-2: Complete POM:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.praveen</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Although, I am still confused by the documentation provided at https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html and was expecting that I should not be required to use JPA for auto-configuration to work if I am explicitly declaring a dependency on HikariCP and Postgresql. Closing it for now.
Your pom is fine if you don't want to use JPA.
Define #Bean for Datasource to configure or add property in application.properties spring.datasource.type=com.zaxxer.hikari.HikariDataSource:
#Configuration
public class DbConfig {
#Bean
#ConfigurationProperties("spring.datasource")
public HikariDataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
}
also change your properties to below:
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username-myself
spring.datasource.password= mypassword
Note: JPA configure for you everything so if not using JPA then you need to configure DataSource by telling about Hikari.
As per reference document 29.1.2 Connection to a Production Database
If you use the spring-boot-starter-jdbc or
spring-boot-starter-data-jpa “starters”, you automatically get a
dependency to HikariCP.
You can bypass that algorithm completely and specify the connection
pool to use by setting the spring.datasource.type property. This is
especially important if you run your application in a Tomcat
container, as tomcat-jdbc is provided by default.
[Tip] Additional connection pools can always be configured manually.
If you define your own DataSource bean, auto-configuration does not
occur.
Related
I get this output will running me spring app
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driver-class-name
Value: com.mysql.cj.jdbc.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
my pom.xml look like this:
<?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.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com</groupId>
<artifactId>couponProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>couponProject-Spring </name>
<description>coupon project part 2 spring</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
and my application.properties looking like this:
spring.datasource.url=jdbc:mysql://localhost:3306/couponproject?serverTimezone=Israel&createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
# spring.jpa.properties.hibernate.format_sql=true
# spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
I'm new to spring so I don't really understand why I get this output
I used spring initializer spring JPA
I read similar questions but I couldn't quite understand the solution
Your project is not able to find the jar because maven dependency is missing for MYSQL Drivers . Please add below dependency for mySQL 8 in order to get the drivers available for your application . Add it inside the <dependencies> section of your pom.xml .
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
Or if you want to have another 8.X or 5.X version MySQL based dependency (based upon which version of MySQL it is that you are using) , please use the correct maven dependency from here : https://mvnrepository.com/artifact/mysql/mysql-connector-java .
I've migrated a Spring Boot project from 2.2.5 to 2.3.0 and after that, Validations stopped to work (they aren't invoked at all).
I read in changelog documentation (https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3.0-M1-Release-Notes), that spring-boot-starter-validation now needs to be added manually as a dependency.
So, I added it to my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
My pom parent is:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath></relativePath>
</parent>
My Controller looks like this:
#PostMapping( value = "/signup", consumes = MediaType.APPLICATION_JSON_VALUE )
#ResponseStatus( value = HttpStatus.OK )
public void signUp( #Valid #RequestBody ClientDto clientDto )
{
onboardingService.signUp( clientDto );
}
EDIT:
I WAS ABLE TO FOUND THE ISSUE, CHECK MY ANSWER BELOW!
Thanks everybody for the help!
Validation starter not included in web starters anymore.
The spring-boot-starter-validation is not a transitive dependency of spring-boot-starter-web and spring-boot-starter-webflux anymore.
Add this dependency for validations work.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
According to spring boot 2.3.1 release
there is no longer contains spring-boot-starter-validation with spring starter
how to add starter validation on
maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Gradle
dependencies {
...
implementation 'org.springframework.boot:spring-boot-starter-validation'
}
referee the release note
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters
If your experiencing the issue of for example: not being able to see the validation errors (default-messages) returned back to the client, this is what you could do:
Top Solution 1:
Simply add devtools. This should solve the issue. After I did this, all my binding-results were returned back to the client. I recommend you to test this out first:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Solution 2:
I found out that this is due to using Spring Boot 2.3+
So if youre using Spring Boot 2.3 or higher, add this dependency in your pom.xml file as its no longer included within the 'web'-dependency itself.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Now its necessary to set 'include binding errors' in java/resources/application.properties to "always". Same goes for 'message' as well although I think this is optional.
server.error.include-message=always
server.error.include-binding-errors=always
Solution 3: (before I discovered solution 2 which could be helpful as well)
So I found out that this is due to having Spring boot 2.3+. But I could not find caution-messages on the new updated usage of #Valid in Spring Boot v2.3+.
So I ended up switching back to Spring boot v2.2.10 (latest version of 2.2) by adjusting the release version in the pom.xml file like so:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
This worked perfectly for me by rolling back to an older version. Although id like to update my Spring Boot version some day. (Revisit solution 1 & 2)
Actually there error was in the unit tests. The validation was working well.
For those who came here with the same issue, it's very likely that you are missing to add the following dependency to the pom.xml as Braian Silva suggested above:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Thanks for your help guys!
Hi You have to annotate you controller class with #Validated annotation see example below:
For testing purpose please try commenting #Validated annotation you won't notice javax.validation.ConstraintViolationException: hello.name: size must be between 4 and 10
but once you place it back its works again.
More technical info here Difference between #Valid and #Validated in Spring
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
#Validated
#RestController
#RequestMapping("/hello")
class HelloController {
#GetMapping
public String hello(#Valid
#NotNull(message = "Name cannot be empty")
#Size(min = 4, max = 10) #RequestParam("name") String name) {
return "Hello, " + name + "!";
}
}
}
<?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.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I've got a similar issue here. But in my case, the validation is warning me that a sequence is missed in oracle schema, but it is there. I think that is a bug.. I will follow with the 2.4.0 version for while..
No one actually solves the same problem. For me, I also added the dependency as instructed above.
The true solution:
Add the dependency
mvn clean install
mvn clean spring-boot:run
Everything works
A simple solution to the above issue is to add:
<repositories>
<repository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
to your POM.xml file.
This will fix the issue with this version
Vipul.
I'm trying to connect a PostgreSQL database to my Spring application but I keep getting errors that are linked with my app not being able to find the org.postgresql.Driver class.
Here's the pom.xml as I proof I'm getting the jar from the dependency:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>slupov</groupId>
<artifactId>slupov-personal</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<finalName>slupov-personal</finalName>
<plugins>
...
</plugins>
</build>
<!-- Spring Boot dependency-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
</parent>
<dependencies>
<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
...
</dependencies>
</project>
I can confirm the downloaded jar contains the org.postgresql.Driver.
Now when I try to check whether the class is in my classpath I get an exception showing it is not there:
try {
Class.forName("org.postgresql.Driver");
//on classpath
} catch(ClassNotFoundException e) {
// breaks here -> not on classpath
System.out.println("Not");
}
Here's my application.properties for the Hibernate connection:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.connection.url=jdbc:postgresql://localhost:5432/SlupovPersonal?useSSL=false
spring.datasource.connection.username=postgres
spring.datasource.connection.password=Sigma255!
spring.datasource.dialect=org.hibernate.dialect.PostgreSQLDialect9.2
spring.datasource.show_sql=true
spring.datasource.current_session_context_class=thread
spring.datasource.hbm2ddl.auto=create
spring.datasource.hibernate.dbcp.initialSize=5
spring.datasource.hibernate.dbcp.maxTotal=20
spring.datasource.hibernate.dbcp.maxIdle=10
spring.datasource.hibernate.dbcp.minIdle=5
spring.datasource.hibernate.dbcp.maxWaitMillis=-1
The
How do I fix this so my app uses the database through Hibernate?
I modified your application.properties to work
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/SlupovPersonal?useSSL=false
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.show_sql=true
spring.jpa.properties.current_session_context_class=thread
spring.jpa.properties.hbm2ddl.auto=create
spring.datasource.dbcp2.initial-size=5
spring.datasource.dbcp2.maxTotal=20
spring.datasource.dbcp2.maxIdle=10
spring.datasource.dbcp2.minIdle=5
spring.datasource.dbcp2.maxWaitMillis=-1
Also we need to change the version of postgressql to a later version as suggested in the second comment or you can remove the version so that it takes the spring boot managed version.
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
I'm trying to create a simple dummy application using Spring Boot Version 1.4.4.
Here is how my pom.xml looks like :
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bootstrap</groupId>
<artifactId>bootstrap</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>tsqln</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
My application class looks like:
package com.bootstrap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TsqlnApplication {
public static void main(String[] args) {
SpringApplication.run(TsqlnApplication.class, args);
}
}
And my application.properties looks like :
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/lostandfound
spring.datasource.username=root
spring.datasource.password=root
But when I run the application I get the following error stating :
*****************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
- Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
Action:
Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.
2017-01-29 17:32:44.645 ERROR 4316 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#516be40f] to prepare test instance [com.bootstrap.TsqlnApplicationTests#9573b3b]**
My directory structure for project is :
However with the same approach the above application works with SpringBoot version 1.3. Any suggestions how to make it work with version 1.4.4?
in your application.properties add this lines
spring.datasource.url = jdbc:mysql://localhost:3306/yourdatabase
# Username and password
spring.datasource.username = root
spring.datasource.password =
# Show or not log for each sql query
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = create
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Make sure your mysql-connector is actually there in the classpath at runtime (if your using Tomcat, then it should be in the lib folder).
If you do not have it there add a compile dependency in your pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
Also you forgot about this line in your application.properties:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
You can restore that behaviour by creating your own datasource bean:
#Bean
public DataSource dataSource() {
return DataSourceBuilder
.create()
.username("")
.password("")
.url("")
.driverClassName("")
.build();
}
I have read various SO question, spring tutorials and looked at different example projects, but i still do not get it.
Among others were these:
unable to connect spring with mysql
http://www.codejava.net/frameworks/spring/spring-mvc-with-jdbctemplate-example
My goal is to get a GRADLE spring boot/web application that connects to my MySql database.
My problem is there are many different ways to configure your project.
I would like to use as few XML as possible.
So my question is, whether it is possible to achieve my goal without having a single XML file and if so - how?
Or if i need an XML file(it should then be the pom.xml I think).
I would like an explanation why I need it and what the file does in general.
Please NOTE: I have about zero knowledge how to configure spring, mysql, hibernate.
So also things that may be straightforward for you, could be unclear to me.
So I would really appreciate explanantions.
EDIT2:
I got an sample application running using Spring Initializer
BUT, this sample application uses Maven - to be exactly it uses this pom.xml:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Is there an eaasy way I can replace this code with gradle or some kind of tutorial that tells me how to replace this code with the correct gradle file?
The simplest way may be for you to download a "bootstrapped" project using the Spring Initializr. You can select the dependencies that you require and the build system, and it will generate your project for you.
For Spring Boot to connect to your MySQL instance, it should be sufficient to just have the following properties in your application.properties file:
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=user
spring.datasource.password=password
See the Spring Boot Reference for Working with SQL databases for more information.