0

I'm trying to set a property in a Spring application (server.port). To do this, the docs says that I need a application.properties file. It says this as it is a default thing for all Java applications. 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/. 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.

Community
  • 1
  • 1
user4419675
  • 63
  • 1
  • 2
  • 5
  • You've to register `PropertiesPlaceholderConfigurer` to load properties file. – Rohit Jain Mar 09 '15 at 15:14
  • @RohitJain Not with spring-boot. (I mean not explicitly. It's done for you.) – Sotirios Delimanolis Mar 09 '15 at 15:15
  • @SotiriosDelimanolis Oh, I didn't know that. In fact, haven't used spring boot till now :) – Rohit Jain Mar 09 '15 at 15:16
  • I'd ask that you provide your configuration and your startup procedure, how you launch your program. If there's a `application.properties` in the root of the classpath, spring-boot will find it. – Sotirios Delimanolis Mar 09 '15 at 15:17
  • another thing to check: How do you build / start / dependency manage your application? Gradle or maven should include the path to the classpath. But if you are building a pure java app with an IDE with plain spring-boot lib (and dependend libs) you have to configure the path inside the IDE (and later by hand for running as a standalone-app). – meistermeier Mar 09 '15 at 15:23
  • @SotiriosDelimanolis, I'm using maven and starting the application with Eclipse. What do you mean with "in the root of the classpath"? My classpath is in `/application/.classpath` and the application.properties file is in `/application/src/main/resources/application.properties` – user4419675 Mar 09 '15 at 15:30
  • @meistermeier, How would I reference the file? I've just placed where the link suggested. I believe that I'm missing how to reference this file. Regarding my environment, I'm following the standard spring.io example using Eclipse and Maven. It is working, but I need to change the server port. – user4419675 Mar 09 '15 at 15:31
  • @SotiriosDelimanolis, thank you! Placing the file at the root of my solution (next to the .classpath file) fixed the problem! If you post this as an answer, I will accept it. – user4419675 Mar 09 '15 at 15:35
  • @user4419675 if your eclipse setup does not respect the resources directory, spring boot will not find the file. I don't know how well eclipse works out of the box with a maven controlled projects and later added conventional folders (like src/main/resources). I think it is just missing from the classpath in the project settings. – meistermeier Mar 09 '15 at 15:45

1 Answers1

0

Considering that you are running Spring Boot,go to application.properties and then set

server.port=8081
Vikram S
  • 551
  • 5
  • 5