简体   繁体   English

我应该如何为Spring创建一个Java application.properties文件?

[英]How should I create a Java application.properties file for Spring?

I'm trying to set a property in a Spring application ( server.port ). 我正在尝试在Spring应用程序( server.port )中设置属性。 To do this, the docs says that I need a application.properties file. 为此, 文档说我需要一个application.properties文件。 It says this as it is a default thing for all Java applications. 它说这是因为这是所有Java应用程序的默认设置。 So, how/where should I create this file? 那么,我应该如何/在何处创建此文件?

I've followed this answer , but I had no success creating the file under /src/main/resources/ . 我已经遵循了这个答案 ,但是在/src/main/resources/下创建文件没有成功。 Is it missing a reference? 是否缺少参考?

EDIT: I had no success because the application still loads using port 8080 instead of the port that I've defined in the configuration file. 编辑:我没有成功,因为应用程序仍然使用端口8080而不是我在配置文件中定义的端口进行加载。

考虑到您正在运行Spring Boot,请转到application.properties ,然后进行设置

server.port=8081

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Spring Boot 应用程序的 application.properties 文件中设置 MyBatis 配置属性? - How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application? 如何在 spring 应用程序中动态修改 application.properties 文件? - How to Modify application.properties file dynamically in spring application? 如何在 spring 引导中创建每个模块 application.properties? - How to create per module application.properties in spring boot? Java Spring-如何通过@WithUserDetails使用application.properties中的值 - Java Spring - How to use value from application.properties with @WithUserDetails 如何在 spring application.properties 中指定我的 ssl 密钥库文件的本地文件路径? - How do I specify local file path to my ssl keystore file in spring application.properties? Spring Boot 2:如何使用application.properties文件配置HikariCP - Spring Boot 2: How to configure HikariCP using application.properties file 如何在 Spring Boot 中访问 application.properties 文件中定义的值 - How to access a value defined in the application.properties file in Spring Boot Spring application.properties文件中的布尔值? - boolean values in Spring application.properties file? Spring boot application.properties 文件读取 - Spring boot application.properties file reading Spring 引导无法识别 application.properties 文件 - Spring Boot not recognizing application.properties file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM