Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I choose the URL for my Spring Boot webapp?

I am using Spring Boot to create a web app, and I am not sure how to change the URL from localhost:8080 to something like localhost:8080/myWebApp.

I have a seen a lot of resources online referencing an application.properties file and adding that to the classpath. But, I'm not sure exactly where to put that.

Questions

  • In my src/main/resources?

  • How would I assign the URL within the file?

like image 868
Theo Avatar asked Jun 27 '14 12:06

Theo


People also ask

What is the URL for spring boot application?

For running the Spring Boot application, open the main application file, and run it as Java Application. When the application runs successfully, it shows the message in the console, as shown below. Now, open the browser and invoke the URL http://localhost:8080.

How do I set URL in application properties?

url=example.com . Then in Your class you do something like: @Service @ConfigurationProperties(prefix="endpoint") public class exampleClass { private String url; //variable name has to match name of the variable definied in application. properties //getter and setter for url is mandatory! }


1 Answers

You need to set the property server.contextPath to /myWebApp.

Check out this part of the documentation

The easiest way to set that property would be in the properties file you are using (most likely application.properties) but Spring Boot provides a whole lot of different way to set properties. Check out this part of the documentation

EDIT

As has been mentioned by @AbdullahKhan, as of Spring Boot 2.x the property has been deprecated and should be replaced with server.servlet.contextPath as has been correctly mentioned in this answer.

like image 142
geoand Avatar answered Sep 26 '22 17:09

geoand