Where is the application.properties file in a Spring Boot project?

后端 未结 4 846
攒了一身酷
攒了一身酷 2020-12-15 02:19

I started a new Spring boot project, I want to change the port number and I read that I have to modify the /resource/application.properties to do so.

I

相关标签:
4条回答
  • 2020-12-15 02:56

    You will need to add the application.properties file in your classpath.

    If you are using Maven or Gradle, you can just put the file under src/main/resources.
    If you are not using Maven or any other build tools, put that under your src folder and you should be fine.

    Then you can just add an entry server.port = xxxx in the properties file.

    0 讨论(0)
  • 2020-12-15 02:58

    You can create it manually but the default location of application.properties is here

    0 讨论(0)
  • 2020-12-15 02:58

    In the your first journey in spring boot project I recommend you to start with Spring Starter Try this link here.

    It will auto generate the project structure for you like this.application.perperties it will be under /resources.

    application.properties important change,

    server.port = Your PORT(XXXX) by default=8080
    server.servlet.context-path=/api (SpringBoot version 2.x.)
    server.contextPath-path=/api (SpringBoot version < 2.x.)

    Any way you can use application.yml in case you don't want to make redundancy properties setting.

    Example
    application.yml

    server:
       port: 8080 
       contextPath: /api
    

    application.properties

    server.port = 8080
    server.contextPath = /api
    
    0 讨论(0)
  • 2020-12-15 03:01

    You can also create the application.properties file manually.

    SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:

    • A /config subdirectory of the current directory.
    • The current directory
    • A classpath /config package
    • The classpath root

    The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations). (From the Spring boot features external configuration doc page)

    So just go ahead and create it

    0 讨论(0)
提交回复
热议问题