0

I want to generate MySQL database with springboot project. I create a maven project, this is the pom.xml:

<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>Springboot</groupId>
<artifactId>ma.mahmoud.springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringBootApps</name>
<description>First project</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.4.RELEASE</version>
</parent>

<properties>
    <hibernate.version>5.0.3.Final</hibernate.version>
    <spring.version>4.2.2.RELEASE</spring.version>
</properties>

<dependencies>

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

    <!-- SPRING -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-collections4</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

<!-- BUILD -->
<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

I create an Entity with javax.persistence annotation, and I create DAO with spring data, a Service and a controller to expose my services.

I add the application.properties in the src/main/resources

server.port=1111
spring.datasource.url=jdbc:mysql://localhost:3306/sping-boot
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop

When i start my application I don't have any error but the database is nit created.

Did I forgot something?

Mahmoud
  • 325
  • 10
  • 25
  • 2
    Possible duplicate of [Unable to get spring boot to automatically create database schema](http://stackoverflow.com/questions/26881739/unable-to-get-spring-boot-to-automatically-create-database-schema) – Patrick Jan 13 '17 at 14:36
  • I think you are right. I have the main class and the entities in different packages and I have not respected the tree. I will dig in this track if it works I will signal to you. – Mahmoud Jan 13 '17 at 14:45
  • 1
    `spring.jpa.hibernate.ddl-auto=create-drop` will drop the tables after the application shuts down. – Sergio Jan 13 '17 at 14:49
  • You aren't using Spring Boot... You are creating a classic war (judging from the plugins you are using) and only use Spring Boot for dependency management. That makes me think those properties are pretty much do nothing at all. – M. Deinum Jan 13 '17 at 14:58

1 Answers1

1

Why did you add that?

   <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>

Please add example the EntityScanConfig class.The @EntityScan on the other hand does not create beans as far as I know. It only identifies which classes should be used by a specific persistence context

@EnableAutoConfiguration
@EntityScan({"com.example.entity.model"})
public class EntityScanConfig {

}
ooozguuur
  • 3,396
  • 2
  • 24
  • 42
  • I add the main class in the parent package "ma.myapps" and the rntity in the child package "ma.myapps.entity" and it's working – Mahmoud Jan 13 '17 at 15:21