Hej, chciałem dodać bazę danych do projektu Spring Boot. Problem jest w tym, że Spring Boot prawidłowo łączy się z bazą danych mysql online, ale nie wykonuje wobec niej utworzenia tablicy student. Baza danych postawiona jest na jakimś freesqldatabase.com, nie mam problemu żeby połączyć się z nią przez IntelliJ Ultimate (próbowałem też z embedded H2, też nie działało)
package com.db.mysql_db_test;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import javax.persistence.*;
@Entity
@Data
@RequiredArgsConstructor
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column
private String name;
}
MysqlDbTestApplication znajduje się w tym samym pakiecie
package com.db.mysql_db_test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
@EntityScan
@SpringBootApplication
public class MysqlDbTestApplication {
public static void main(String[] args) {
SpringApplication.run(MysqlDbTestApplication.class, args);
}
}
application.properties (próbowałem już chyba wszystkich możliwych kombinacji)
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://sql7.freesqldatabase.com:3306/sql7617804
spring.datasource.username=sql7617804
spring.datasource.password=Ta4mIZ6Be3
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>3.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.db</groupId>
<artifactId>mysql_db_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mysql_db_test</name>
<description>mysql_db_test</description>
<properties>
<java.version>17</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Nie wiem, w którym miejscu pojawia się ten problem. Utworzyłem świeży projekt, idę krok po kroku z poradnikiem na YT i wciąż nie działa.
Mógłbym oczywiście obejść ten problem, ręcznie tworząc tablicę (CREATE TABLE...), ale chcę tego uniknąć, bo po to chyba jest jpa żeby wszystko było uproszczone.