I did:
- created project with some dependencies.
- created first maven module(web).
- created second maven module(model).
- moved code to web module: main class + controller.
- deleted src from root(because it is already empty)
- in model module created entity, added dependencies JPA/MySQl driver to pom.xml of this module.
- in web module added dependency of model module.
Project runs without errors, web module sees model dependency. But code of entity doesnt work(not creating table in database). If i move class to web module - it works. Exactly - it works, but dependencies of JPA/MySQL are still in model module.
What i am doing wrong?
I tried to change names of groupId and artifactId, with package`s names of modules, moved application.propeties to model module - does not help.
My project:
-model/src/main/java and resources/com/example/demo/model
pom.xml:
<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.demo.model</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>module-model</name>
<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>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
-web/src/main/java and resources/com/example/demo/web
application.properties with database connection to MySQL.
pom.xml
<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.demo.web</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>module-web</name>
<description>Web project</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.example.demo.model</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
Main pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<description>Demo project for Spring Boot</description>
<name>demo</name>
<modules>
<module>web</module>
<module>model</module>
</modules>