5

I'm developing a simple api with three endpoints using vertx.

That api has some predefined tests that I cannot modify and I need to pass, which use:

@Autowired
private GenericWebApplicationContext webApplicationContext;
private MockMvc mockMvc;

After finishing the api I found that as I'm using verticles I don't need the embedded tomcat which provides spring boot starter dependency, so I removed it.

Which is my problem?

I cannot exclude embedded tomcat because spring boot needs it, otherwise I will get the following error: The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured. as vertx verticle and tomcat listen to the same port (8080).

The problem here is that I can change verticle port to 8081 for example, but the tests will need to be executed to the port 8080. How can I fix that, so that tests listen for verticle that I deploy (which creates an http server too)?

Basically I would like to know if it possible that MockHttpServletResponse uses vertx server which is created by verticle instead of embedded tomcat.

Gerardo
  • 175
  • 1
  • 2
  • 9

2 Answers2

0

The problem can be in your pom.xml and in your @Configuration class. Try this dependency add to your pom.xml . So when u deploy your war file to your server it will run normal tomcat instead of embeded

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

and in your Application class write this

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

public static void main(String[] args) {

    SpringApplication.run(Application.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
}

}

. Then problem which are you facing that tomcat is already started so it listen on port 8080 and you try to run another tomcat which will listen on the same problem.

You have to shutdown old tomcat instance if you want start new

  • I tried that but I'm getting the following error when running `mvn clean spring-boot:run`: `org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8080]]` – Gerardo Sep 15 '18 at 13:30
0

In your application.properties file put server.port=8080 or 8082 you can see the which process is using the port using command prompt using netstat -a-o-n and terminate it

Vishal Torne
  • 366
  • 5
  • 24
  • 4
    That's not a problem, my vertx verticle is running on 8081 and embedded tomcat on 8080. The problem is that mockMvc only performs requests on embedded tomcat instead of my verticle, and I would like to use only the vertx http server not the embedded tomcat. – Gerardo Sep 15 '18 at 14:21