1

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?

Vasu
  • 21,832
  • 11
  • 51
  • 67
AlexP
  • 449
  • 2
  • 9
  • 25

2 Answers2

5

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.

Community
  • 1
  • 1
Vasu
  • 21,832
  • 11
  • 51
  • 67
  • Ok setting Tomcat is more difficult as I expected. But what change I need to do to use embedded servlet container? – AlexP Apr 11 '17 at 19:42
  • yes, if you wanted the from `application.properties`, you need embedded servlet container and try it following the link, it is very easy – Vasu Apr 11 '17 at 19:43
  • Not yet :( I have create Application class and one Controller class, but launching it on Spring Boot App it gives me an error : nodename nor servname provided, or not known – AlexP Apr 11 '17 at 19:55
  • It would be a good idea to close this and open a new question with that error as it is a separate issue – Vasu Apr 11 '17 at 20:14
  • I agree. Close this question, since your question was answered. – rob Apr 11 '17 at 20:16
0

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

AlexP
  • 449
  • 2
  • 9
  • 25