Spring doesn't create the table specified in my #Entity class in my MySQL database.
I've tried a lot of solutions given here in StackOverflow, like some changes in the application.properties, changing the dialect, setting up the schema etc. I've checked my database permissions and also the user/password information, and it's all fine.
application.properties:
spring.datasource.url=jdbc:mysql://localhost/MyBank?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
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 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.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>MyBanc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MyBanc</name>
<description>JEE spring boot Web Project by Zied </description>
<properties>
<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-security</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-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>
Client.java
package com.example.entities;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Collection;
#Entity
public class Client implements Serializable {
#Id #GeneratedValue
private long code;
private String nom;
private String email;
#OneToMany(mappedBy = "client",fetch = FetchType.LAZY)
private Collection<Compte> comptes;
public Client() {
super();
}
public Client(String nom, String email) {
super();
this.nom = nom;
this.email = email;
}
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Collection<Compte> getComptes() {
return comptes;
}
public void setComptes(Collection<Compte> comptes) {
this.comptes = comptes;
}
}
terminal:
2019-12-16 14:24:38.857 INFO 6812 --- [ restartedMain] com.example.MyBank.MyBankApplication : Starting MyBankApplication on DESKTOP-BLK0G7N with PID 6812 (C:\Users\ziedb\OneDrive\Bureau\aa\MyBank\target\classes started by Zied BenOthman in C:\Users\ziedb\OneDrive\Bureau\aa\MyBank)
2019-12-16 14:24:38.862 INFO 6812 --- [ restartedMain] com.example.MyBank.MyBankApplication : No active profile set, falling back to default profiles: default
2019-12-16 14:24:38.935 INFO 6812 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\ziedb\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/C:/Users/ziedb/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/C:/Users/ziedb/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/C:/Users/ziedb/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/C:/Users/ziedb/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/C:/Users/ziedb/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/C:/Users/ziedb/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2019-12-16 14:24:38.936 INFO 6812 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-12-16 14:24:38.936 INFO 6812 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-12-16 14:24:39.539 INFO 6812 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2019-12-16 14:24:39.557 INFO 6812 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10ms. Found 0 JPA repository interfaces.
2019-12-16 14:24:39.809 INFO 6812 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-12-16 14:24:40.083 INFO 6812 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-12-16 14:24:40.091 INFO 6812 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-12-16 14:24:40.091 INFO 6812 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-16 14:24:40.169 INFO 6812 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-16 14:24:40.169 INFO 6812 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1233 ms
2019-12-16 14:24:40.288 INFO 6812 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2019-12-16 14:24:40.346 INFO 6812 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}
2019-12-16 14:24:40.469 INFO 6812 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-12-16 14:24:40.627 INFO 6812 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-12-16 14:24:40.754 INFO 6812 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-12-16 14:24:40.769 INFO 6812 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-12-16 14:24:40.977 INFO 6812 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-12-16 14:24:40.984 INFO 6812 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-12-16 14:24:41.019 INFO 6812 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-12-16 14:24:41.072 WARN 6812 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-12-16 14:24:41.236 INFO 6812 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-16 14:24:41.388 WARN 6812 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2019-12-16 14:24:41.550 INFO 6812 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-12-16 14:24:41.553 INFO 6812 --- [ restartedMain] com.example.MyBank.MyBankApplication : Started MyBankApplication in 3.075 seconds (JVM running for 3.971)
Based on the tutorial that I'm following, this setup should result in the creation of the table in the MySQL database, but it doesn't happen.
There are some possible causes for this:
The application.properties file is not in the correct location. It
should be located in src/main/resources
Second problem: The entity class. You should add #Column on top of
the attributes
Move the entity package to become like org.example.entities and run
the app
In spring application you should create one pakcage for the one layer(entity, repository,service ...)
I think you can simplify this to achieve first a JDBC CRUD:
Remove all the unnecessary maven dependencies, only have following to begin with :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MySQL connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- in case you wanna add Junits-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
Then have following in your application.properties
spring.datasource.url=jdbc:mysql://localhost:yourMySQLPort/MyBank?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.use-new-id-generator-mappings=false
spring.jpa.hibernate.ddl-auto=create
Take care of auto-generation of id of your entity:
#Entity
public class Client implements Serializable {
#Id #GeneratedValue(strategy = GenerationType.AUTO)
private long code;
...
And to keep things simple initially, maintain the Main class i.e Spring boot starter class annotated with #SpringBootApplication in the same package as your entity Client
I've noticed that you haven't mentioned the MySQL server port in your URL, see if thats something that is not initiating the connection. Once you get this sorted, you can add up the rest of the features in your app (thymeleaf based viewing tech etc)
Hope this helps!
Related
im building CRUD app but ran into a problem . When I start the application at http://localhost:8080/api/v1/employees i recieve a whitelabel error 404 instead JSON response with db data .
Message
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Sep 08 17:49:26 GST 2022
There was an unexpected error (type=Not Found, status=404).
No message available
Controller
package com.crudpet.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.crudpet.model.Employee;
import com.crudpet.repository.EmployeeRepository;
#RestController
#RequestMapping("/api/v1/")
public class EmployeeController {
#Autowired
private EmployeeRepository employeeRepository;
#GetMapping("/employees")
public List<Employee> getAllEmployees(){
return employeeRepository.findAll();
}
}
main class
package com.crudpet.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
public class SpringbootBackendCrudApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootBackendCrudApplication.class, args);
}
}
console
2022-09-08 17:49:19.486 INFO 836 --- [ restartedMain] c.c.s.SpringbootBackendCrudApplication : Starting SpringbootBackendCrudApplication using Java 17.0.1 on DESKTOP-08M3S29 with PID 836 (C:\Users\Bogich\Documents\workspace-spring-tool-suite-4-4.13.1.RELEASE\springboot-backend-crud\target\classes started by Bogich in C:\Users\Bogich\Documents\workspace-spring-tool-suite-4-4.13.1.RELEASE\springboot-backend-crud)
2022-09-08 17:49:19.487 INFO 836 --- [ restartedMain] c.c.s.SpringbootBackendCrudApplication : No active profile set, falling back to 1 default profile: "default"
2022-09-08 17:49:19.556 INFO 836 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-09-08 17:49:19.556 INFO 836 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-09-08 17:49:20.206 INFO 836 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-09-08 17:49:20.223 INFO 836 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces.
2022-09-08 17:49:20.833 INFO 836 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-09-08 17:49:20.844 INFO 836 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-09-08 17:49:20.844 INFO 836 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-09-08 17:49:20.917 INFO 836 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-09-08 17:49:20.917 INFO 836 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1360 ms
2022-09-08 17:49:21.132 INFO 836 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-09-08 17:49:21.193 INFO 836 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-09-08 17:49:21.388 INFO 836 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-09-08 17:49:21.507 INFO 836 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-09-08 17:49:21.684 INFO 836 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-09-08 17:49:21.701 INFO 836 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2022-09-08 17:49:21.988 INFO 836 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-09-08 17:49:21.999 INFO 836 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-09-08 17:49:22.063 WARN 836 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-09-08 17:49:22.450 INFO 836 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-09-08 17:49:22.492 INFO 836 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-09-08 17:49:22.502 INFO 836 --- [ restartedMain] c.c.s.SpringbootBackendCrudApplication : Started SpringbootBackendCrudApplication in 3.407 seconds (JVM running for 4.229)
2022-09-08 17:49:26.819 INFO 836 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-09-08 17:49:26.819 INFO 836 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-09-08 17:49:26.820 INFO 836 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
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 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.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.crudpet</groupId>
<artifactId>springboot-backend-crud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-backend-crud</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
The problem is when i start app i must recieve a JSON response but i see Whitelabel error.
I've tried ComponentScan , but it is not work for me.
What i must do?
You haven't specified the package name in your controller and main classes.
The default Spring auto-discovery won't work because of this, and your controller won't be instantiated. Spring looks for the components under the packages specified classes. Without the specified package, Spring won't be able to 'see' your beans and add them to ApplicationContext.
Simply add the package statement at the top of your class and everything should start working correctly.
Example:
package com.example;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.crudpet.model.Employee;
import com.crudpet.repository.EmployeeRepository;
#RestController
#RequestMapping("/api/v1/")
public class EmployeeController {
#Autowired
private EmployeeRepository employeeRepository;
#GetMapping("/employees")
public List<Employee> getAllEmployees(){
return employeeRepository.findAll();
}
}
Updated:
Your main class SpringbootBackendCrudApplication, which is marked as #SpringBootApplication is located in the package com.crudpet.springboot. Whereas your controller is located in the com.crudpet.controller package.
By default, Spring Boot will scan for beans in the base package of the class with main method (SpringbootBackendCrudApplication in your case) and all nested packages (e.g., com.crudpet.springboot.example). The com.crudpet.controller package with your controller class is out of scope and simply wasn't initiated.
To fix this, you need to place the SpringbootBackendCrudApplication class in the com.crudpet package, which is best practice. Another possible solution is explicitly specifying the com.crudpet.controller package in the component scan.
I am new to Spring boot and just trying to create the tables using hibernate in spring boot but Unable to do so. Below are my code and configurations
User.java (Entity)
#Entity
#Table(name = "users")
public class User {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String userName;
private String password;
private String first_name;
private String lastName;
private String email;
private String phone;
private boolean enabled = true;
}
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 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.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rafey</groupId>
<artifactId>examback</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>examback</name>
<description>backend for exam portal.</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-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>
application.properties file
#database configuration
spring.datasource.url = jdbc:mysql://localhost:3306/examportal
spring.datasource.username = root
spring.datasource.password =
spring.datasource.driver-class = com.cj.jdbc.Driver
#JPA configuration
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.open-in-view
these are the logs
2022-09-05 03:21:44.420 INFO 5320 --- [ main] com.rafey.examback.ExambackApplication : Starting ExambackApplication using Java 11.0.16 on Abdur-PC with PID 5320 (C:\Users\Rafey\Desktop\examportal\examback\examback\target\classes started by Rafey in C:\Users\Rafey\Desktop\examportal\examback\examback)
2022-09-05 03:21:44.427 INFO 5320 --- [ main] com.rafey.examback.ExambackApplication : No active profile set, falling back to 1 default profile: "default"
2022-09-05 03:21:45.676 INFO 5320 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-09-05 03:21:45.714 INFO 5320 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 13 ms. Found 0 JPA repository interfaces.
2022-09-05 03:21:47.194 INFO 5320 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-09-05 03:21:47.216 INFO 5320 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-09-05 03:21:47.216 INFO 5320 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-09-05 03:21:47.539 INFO 5320 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-09-05 03:21:47.540 INFO 5320 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2992 ms
2022-09-05 03:21:47.934 INFO 5320 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-09-05 03:21:48.018 INFO 5320 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-09-05 03:21:48.270 INFO 5320 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-09-05 03:21:48.417 INFO 5320 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-09-05 03:21:48.996 INFO 5320 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-09-05 03:21:49.019 INFO 5320 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2022-09-05 03:21:49.391 INFO 5320 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-09-05 03:21:49.416 INFO 5320 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-09-05 03:21:50.098 INFO 5320 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-09-05 03:21:50.114 INFO 5320 --- [ main] com.rafey.examback.ExambackApplication : Started ExambackApplication in 6.728 seconds (JVM running for 7.678)
This is my main class
#SpringBootApplication
public class ExambackApplication {
public static void main(String[] args) {
SpringApplication.run(ExambackApplication.class, args);
}
}
help me resolving this issue. Thanks
Yo, cant resolve this simply problem in h2-console..
I want just create table via Entity class like "MOvie" or "director" but when i open my h2-console,is not created, pls help
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 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.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>sk.wynny</groupId>
<artifactId>springLearn</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springLearn</name>
<description>Demo project for Spring Boot</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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</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>
app-properties
spring.h2.console.enabled= true
spring.datasource.url=jdbc:h2:mem:wynny
spring.datasource.username=root
MOVIE CLASS
package sk.wynny.modul;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class Movie {
#Id
#GeneratedValue
private Long id;
private String name;
public Movie() {
}
public Movie(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
LOGs
2022-02-13 20:11:37.031 INFO 5856 --- [ main] s.w.springLearn.SpringLearnApplication : Starting SpringLearnApplication using Java 17.0.1 on DESKTOP-K3O8I67 with PID 5856 (C:\Users\Patrik Severín\IdeaProjects\springLearn\target\classes started by Wynny in C:\Users\Patrik Severín\IdeaProjects\springLearn)
2022-02-13 20:11:37.034 INFO 5856 --- [ main] s.w.springLearn.SpringLearnApplication : No active profile set, falling back to default profiles: default
2022-02-13 20:11:37.638 INFO 5856 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-02-13 20:11:37.653 INFO 5856 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 5 ms. Found 0 JPA repository interfaces.
2022-02-13 20:11:38.249 INFO 5856 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-02-13 20:11:38.260 INFO 5856 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-13 20:11:38.260 INFO 5856 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-02-13 20:11:38.362 INFO 5856 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-13 20:11:38.363 INFO 5856 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1281 ms
2022-02-13 20:11:38.398 INFO 5856 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-02-13 20:11:38.553 INFO 5856 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-02-13 20:11:38.563 INFO 5856 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:wynny'
2022-02-13 20:11:38.735 INFO 5856 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-02-13 20:11:38.789 INFO 5856 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.4.Final
2022-02-13 20:11:38.949 INFO 5856 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-02-13 20:11:39.073 INFO 5856 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-02-13 20:11:39.263 INFO 5856 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-02-13 20:11:39.273 INFO 5856 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-02-13 20:11:39.321 WARN 5856 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-02-13 20:11:39.602 WARN 5856 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2022-02-13 20:11:39.734 INFO 5856 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-02-13 20:11:39.746 INFO 5856 --- [ main] s.w.springLearn.SpringLearnApplication : Started SpringLearnApplication in 3.068 seconds (JVM running for 3.417)
i following many videos or manuals and still have same problem, is here some Hero what can resolve it ? :D
Problem was in Thymeleaf engine, if i create spring only with h2,web and jpa is working nicely.Idk why problem is with Thymeleaf..
I have a Springboot project I created by copying the libraries from mvn repository, not using SPRING INITLZR.
Anyway Springboot main seems to be working fine.
It's just that my Rest Controller is not displaying the message I want to.
Main.class
#SpringBootApplication
public class MovieInfoServiceApplication {
public static void main(String[] args) throws IOException, GeneralSecurityException, MessagingException {
SpringApplication.run(MovieInfoServiceApplication.class, args);
}
}
RestController.class
#RestController
#RequestMapping("/")
public class MovieServiceRestController {
#GetMapping("/hello")
//#CrossOrigin(origins = "http://localhost:9005")
public String hello() {
return "movie-service-api: hello from MovieServiceRestController";
}
}
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 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.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.backend</groupId>
<artifactId>movie-info-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>movie-info-service</name>
<description>microservices about movie info</description>
<properties>
<java.version>11</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-web-services</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>
This is what I got when I access "localhost:9005/hello"
Springboot logs
2020-10-18 02:18:35.481 INFO 4347 --- [ main] com.gmailapijava.main.GmailAPIJavaMain : No active profile set, falling back to default profiles: default
2020-10-18 02:18:38.779 INFO 4347 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$e708c1d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-18 02:18:39.142 INFO 4347 --- [ main] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2020-10-18 02:18:40.286 INFO 4347 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9005 (http)
2020-10-18 02:18:40.307 INFO 4347 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-10-18 02:18:40.307 INFO 4347 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-10-18 02:18:41.175 INFO 4347 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-10-18 02:18:41.176 INFO 4347 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5020 ms
2020-10-18 02:18:42.329 INFO 4347 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-10-18 02:18:43.369 INFO 4347 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9005 (http) with context path ''
2020-10-18 02:18:43.391 INFO 4347 --- [ main] com.gmailapijava.main.GmailAPIJavaMain : Started GmailAPIJavaMain in 10.504 seconds (JVM running for 14.339)
2020-10-18 02:18:56.903 INFO 4347 --- [nio-9005-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-10-18 02:18:56.905 INFO 4347 --- [nio-9005-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-10-18 02:18:56.919 INFO 4347 --- [nio-9005-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 14 ms
SpringApplication.run(GmailAPIJavaMain.class, args);
should be
SpringApplication.run(MovieInfoServiceApplication.class, args);
Also check if the controller package is getting scanned.
Try it like this
#RestController
public class MovieServiceRestController {
#GetMapping("/hello")
//#CrossOrigin(origins = "http://localhost:9005")
public String hello() {
return "movie-service-api: hello from MovieServiceRestController";
}
}
I try to save object in Postgresql database but unsuccesfully. Application starts normally, no exception is thrown and companiesRepository is not null. The database has been created manually.
This is my Application.class:
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
This is my Service.class:
#org.springframework.stereotype.Service
public class Service {
#Autowired
CompaniesRepository companiesRepository;
public void start() {
Companies companies = new Companies();
companies.setSomeString("some");
companies.setId(1);
companiesRepository.save(companies);
log.info("Companies saved in DB");
}
}
This is my Companies.class:
#Entity
#Data
public class Companies {
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Id
Integer id;
String someString;
}
This is my CompaniesRepository interface:
#Repository
public interface CompaniesRepository extends CrudRepository<Companies, Integer> {
}
This is my Controller.class:
#RestController
public class Controller {
#Autowired
private Service service;
#RequestMapping("/")
public String start() throws Exception {
service.start();
return "App Started";
}
}
The configuration I have in bootstrap.yaml file works properly in another project:
spring:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
show-sql: false
generate-ddl: true
time_zone: UTC
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hbm2ddl:
auto: update
jdbc:
lob:
non_contextual_creation: true
enable_lazy_load_no_trans: true
datasource:
url: jdbc:postgresql://localhost:5432/dos?createDatabaseIfNotExist=true&serverTimezone=UTC
driver-class-name: org.postgresql.Driver
username: "postgres"
password: "123"
initialization-mode: always
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
jdbc:
time_zone: UTC
I tried to:
annottate String and id in Companies.class with #Column(nullable = false),
changed table name for Companies.class with #Table(name = "some_table").
add #Autowired CompaniesRepository repository; in Controller.class
EDIT:
Those are the console logs:
2020-03-07 15:35:11.620 INFO 2484 --- [ main] com.xtb.tradebot.Application : Starting Application on MWNB00049 with PID 2484 (C:\Users\Piotr\Documents\trade-bot\trade-bot\target\classes started by Piotr in C:\Users\Piotr\Documents\trade-bot\trade-bot)
2020-03-07 15:35:11.622 INFO 2484 --- [ main] com.xtb.tradebot.Application : No active profile set, falling back to default profiles: default
2020-03-07 15:35:12.179 INFO 2484 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-07 15:35:12.255 INFO 2484 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 63ms. Found 1 JPA repository interfaces.
2020-03-07 15:35:12.638 INFO 2484 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-07 15:35:13.123 INFO 2484 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-07 15:35:13.137 INFO 2484 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-07 15:35:13.137 INFO 2484 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-03-07 15:35:13.226 INFO 2484 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-07 15:35:13.226 INFO 2484 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1563 ms
2020-03-07 15:35:13.390 INFO 2484 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-07 15:35:13.673 INFO 2484 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-03-07 15:35:13.735 INFO 2484 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-03-07 15:35:13.830 INFO 2484 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final}
2020-03-07 15:35:13.995 INFO 2484 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-07 15:35:14.131 INFO 2484 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-03-07 15:35:14.731 INFO 2484 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-03-07 15:35:14.735 INFO 2484 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-07 15:35:15.011 WARN 2484 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-07 15:35:15.134 INFO 2484 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-07 15:35:15.369 INFO 2484 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-07 15:35:15.371 INFO 2484 --- [ main] com.xtb.tradebot.Application : Started Application in 4.035 seconds (JVM running for 4.357)
Logs after controller "/" endpoint called:
2020-03-07 16:28:40.365 INFO 20336 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-07 16:28:40.365 INFO 20336 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-03-07 16:28:40.374 INFO 20336 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 9 ms
This is 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 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.2.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.xtb</groupId>
<artifactId>trade-bot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>trade-bot</name>
<description>trade-bot</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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</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 deleted h2.database dependency and I added:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
And I added in bootstrap.yaml:
spring:
main:
allow-bean-definition-overriding: true
And now it works fine.