У меня есть простое приложение для весенней загрузки, в котором я пытаюсь использовать модули java 11. Все работает нормально, пока я не добавлю соединение с базой данных. Я пробовал использовать H2 и MySql, но всегда получаю следующую ошибку:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.context@5.1.7.RELEASE/org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.7.RELEASE.jar:na]
at spring.context@5.1.7.RELEASE/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.7.RELEASE.jar:na]
at spring.context@5.1.7.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.7.RELEASE.jar:na]
at spring.boot@2.1.5.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.5.RELEASE.jar:na]
at spring.boot@2.1.5.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.5.RELEASE.jar:na]
at spring.boot@2.1.5.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.5.RELEASE.jar:na]
at spring.boot@2.1.5.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.5.RELEASE.jar:na]
at spring.boot@2.1.5.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar:na]
at spring.boot@2.1.5.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar:na]
at com.north.resource/com.north.resource.ResourceApplication.main(ResourceApplication.java:16) ~[classes/:na]
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at spring.orm@5.1.7.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:640) ~[spring-orm-5.1.7.RELEASE.jar:na]
at spring.orm@5.1.7.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:462) ~[spring-orm-5.1.7.RELEASE.jar:na]
at spring.orm@5.1.7.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:443) ~[spring-orm-5.1.7.RELEASE.jar:na]
at spring.orm@5.1.7.RELEASE/org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328) ~[spring-orm-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.7.RELEASE.jar:na]
at spring.beans@5.1.7.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.7.RELEASE.jar:na]
... 16 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
at spring.core@5.1.7.RELEASE/org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195) ~[spring-core-5.1.7.RELEASE.jar:na]
at spring.orm@5.1.7.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:636) ~[spring-orm-5.1.7.RELEASE.jar:na]
... 21 common frames omitted
Process finished with exit code 1
У меня три модуля:
- resource
- service
- репозиторий
Модуль ресурсов - это мой основной модуль, в котором у меня есть класс записи. Файл application.properties находится в этом модуле:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/modular
spring.datasource.username=root
spring.datasource.password=
Это файл 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>
<dependencies>
<dependency>
<groupId>com.north</groupId>
<artifactId>service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<parent>
<groupId>com.north</groupId>
<artifactId>modularity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>resource</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>resource</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
А это родительский pom file:
<?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.1.5.RELEASE</version>
</parent>
<groupId>com.north</groupId>
<artifactId>modularity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>modularity</name>
<description>Demo project for Spring Boot</description>
<packaging>pom</packaging>
<modules>
<module>resource</module>
<module>service</module>
<module>repository</module>
</modules>
<properties>
<java.version>1.11</java.version>
<maven.test.skip>true</maven.test.skip>
<maven.compiler.version>3.8.1</maven.compiler.version>
<lombok.version>1.18.8</lombok.version>
<start-class>com.module.main.Main</start-class>
</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>
<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>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Я провел собственное расследование и думаю, что моя проблема в том, что application.properties находится в модуле, и это причина, по которой он не может разрешить URL-адрес. Даже если я удалю два других модуля и получу только чистый код с application.properties и одним модулем (ресурсом), я все равно получаю ту же ошибку.