我在Spring Boot 2.2.0.M4 Java 14 Gradle项目中创建了一个新应用: 当我添加application.properties文件
server.port=9001
一切正常。
Tomcat initialized with port(s): 9001 (http)
当我将module-info.java文件添加到项目中时:
module demo.main {
requires java.persistence;
requires static lombok;
requires java.validation;
requires org.hibernate.validator;
requires java.sql;
requires spring.boot;
requires java.xml.bind;
requires net.bytebuddy;
requires com.fasterxml.classmate;
requires spring.boot.starter;
requires spring.boot.autoconfigure;
opens org.demo
}
应用程序从端口8080启动:
Tomcat initialized with port(s): 8080 (http)
不会读取整个application.properties文件并将其应用于项目。
当我从项目中删除module-info.java文件时,一切开始正常运行。
build.gradle in root folder
module-info.java file in root/src/main/java
application.properties file in root/src/main/resources
如果我添加:
@PropertySources(
@PropertySource("classpath:application.properties")
)
顶部:
public class PortalApplication {
public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
}
在没有module-info.java文件的项目中,一切正常:
Tomcat initialized with port(s): 9001 (http)
当我将相同的代码添加到带有module-info.java文件的项目中时:
2019-07-19 12:15:29.329 INFO 32502 --- [ main] o.o.portalapp.portal.PortalApplication : Starting PortalApplication on AMDC2024 with PID 32502 (/home/d.mizyn/portal/out/production/classes started by d.mizyn in /home/d.mizyn/portal)
2019-07-19 12:15:29.332 INFO 32502 --- [ main] o.o.portalapp.portal.PortalApplication : No active profile set, falling back to default profiles: default
2019-07-19 12:15:29.488 WARN 32502 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [org.onap.portalapp.portal.PortalApplication]; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
2019-07-19 12:15:29.497 ERROR 32502 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [org.onap.portalapp.portal.PortalApplication]; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
at spring.context@5.2.0.M3/org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184) ~[spring-context-5.2.0.M3.jar:na]
我尝试添加:
requires java.transaction;
在我的module-info.java文件中,该问题的含义如下:
findResource("") returning null when module-info.java is present, why is that?
没有帮助。
所以,我的问题是: 如何在不使用命令行参数的情况下更改模块化项目中的server.port:
java -jar demo.jar --server.port=9001
[解决方案] 将application.properties文件移至root / config文件夹