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?

4
  • 2
    Possible duplicate of Unable to get spring boot to automatically create database schema Commented Jan 13, 2017 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. Commented Jan 13, 2017 at 14:45
  • 1
    spring.jpa.hibernate.ddl-auto=create-drop will drop the tables after the application shuts down. Commented Jan 13, 2017 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. Commented Jan 13, 2017 at 14:58

1 Answer 1

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 {

}
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.