I am totally new to Spring and started to do the official guides from this site: https://spring.io/guides
I\'d like to do this guide: https://spring.io/guides/gs/sch
Problem is exclusion of starter tomcat, I tried exclude it and use vert.x, so when I integrate wit Spring Admin, started problems
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
The error suggests that the application you are trying to run cannot instantiate an instance of apache tomcat. Make sure you are running the application with tomcat.
if after checking all your dependencies you experience the same problem, try to add the following in your configuration class
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory =
new TomcatEmbeddedServletContainerFactory();
return factory;
}
If you are using an external instance of tomcat (especially for intellij), the problem could be that the IDE is trying to start the embedded tomcat. In this case, remove the following from your pom.xml then configure the external tomcat using the 'Edit Configurations' wizard.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Adding the spring boot starter dependency fixed my error.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
This is required if you want to start the tomcat as an embeded server.
A SpringApplication
will attempt to create the right type of ApplicationContext
on your behalf. By default, an AnnotationConfigApplicationContext
or AnnotationConfigEmbeddedWebApplicationContext
will be used, depending on whether you are developing a web application or not.
The algorithm used to determine a ‘web environment’ is fairly simplistic (based on the presence of a few classes). You can use setWebEnvironment(boolean webEnvironment)
if you need to override the default.
It is also possible to take complete control of the ApplicationContext
type that will be used by calling setApplicationContextClass(…)
.
[Tip]
It is often desirable to call setWebEnvironment(false)
when using SpringApplication
within a JUnit test.
This should be caused by dependency issue, in general, you need to check the dependency.
use this one in your pom.xml :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
or this one :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>