AlexP
AlexP

Reputation: 459

Spring boot change server port

I have created Spring Maven project (using archetype maven-archetype-webapp) for web application. I need to bind on ip different from localhost and different port. I have created file "application.properties" in resources folder and added following lines:

server.port=8001
server.address= 192.168.1.91

However on startup it still uses port default one 8080 and also ip is still localhost.

My WebInitializer class is :

package guard;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{RootConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"*.html"};
    }

}

What am I doing wrong?

Upvotes: 2

Views: 6937

Answers (2)

AlexP
AlexP

Reputation: 459

Actually the easiest way is to change Tomcat setting by server.xml file and there change port

<Connector connectionTimeout="20000" port="8000" protocol="HTTP/1.1" redirectPort="8443"/>

To change IP it is enough to using Spring click on Tomcat properties and change Host name to local IP

Upvotes: 0

Vasu
Vasu

Reputation: 22402

No, you can't change the server port unless you are using an embedded servlet container i.e, if you are deploying your web application (war) directly into Tomcat, then changing the port number in application.properties will not simply work. For this, you need to change the port in Tomcat server's server.xml. Also, if you wanted to configure the Tomcat server IP address then, you can look here.

You can look here on how embedded servlet containers can be hosted so that you can use application.properties to configure IP and port details.

Upvotes: 6

Related Questions