首页 文章

buildin spring boot项目后server.port属性不起作用

提问于
浏览
0

我正在开发spring boot项目,一切正常,现在我想构建并运行应用程序 . 在application.properties文件中,我在使用maven构建项目后设置属性 server.port = 8090 我运行以下命令 java -jar jarfilename.jar 但它说端口 8080 已在使用中 . 我尝试这些命令:

java -jar  -Dport=8090 jarfilename.jar

java -jar  jarfilename.jar --port=8090

但我也得到了相同的消息,端口 8080 已经在使用中 .

我想知道为什么它需要端口号 8080 并忽略我在application.properties文件中设置的端口号 8090 .

注意:(我'm using tomcat embedded server) and when i check the folder target/classes.. application.properties i didn't找到属性 server.port=8090 .

任何人都可以向我解释什么是'exacly?提前致谢 .

1 回答

  • 4

    application.properties位于正确的位置吗? Spring.io的描述:

    SpringApplication将从以下位置的application.properties文件加载属性,并将它们添加到Spring Environment:当前目录的A / config子目录 . 当前目录A classpath / config包类路径根列表按优先级排序(在列表中较高位置定义的属性将覆盖在较低位置定义的属性) .

    使用 java -jar -Dserver.port=8090 jarfilename.jar 从命令行设置端口 .

    提示,来自Spring.io:如果要使用短期 -Dport=8090 ,可以在应用程序属性文件中使用 server.port=${port:8080} .

相关问题