Reputation: 575
Spring Boot application fails to launch after upgrade from 1.3.3 to 1.3.5. Spring is unable to start embedded container (Tomcat 8) and following error message is displayed:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedServletContainerFactory': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [wad.config.HttpsConfiguration$1]: No default constructor found; nested exception is java.lang.NoSuchMethodException: wad.config.HttpsConfiguration$1.()
Basically this error message says it can't create the embeddedServletContainerFactory
, but it's not clear to me what [wad.config.HttpsConfiguration$1]
refers to. The Java configuration class itself is in package wad.config
and named HttpsConfiguration
.
I tried to add empty constructor to my HttpsConfiguration.java
but it didn't help.
Here are the relevant parts of my POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
...
</dependencies>
My Application class:
@EntityScan(
basePackageClasses = {Application.class, Jsr310JpaConverters.class}
)
@SpringBootApplication
@Import({DevProfile.class})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
And here is my configuration for port redirect from 8080 -> 8443 (configurable via application.properties):
@Configuration
public class HttpsConfiguration {
@Value("${server.port}")
private int httpsPort;
@Value("${server.port.http}")
private int httpPort;
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
return tomcat;
}
// redirect from (http) port to (https) if https is enabled.
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(httpPort);
connector.setSecure(false);
connector.setRedirectPort(httpsPort);
return connector;
}
application.properties config:
...
#Actuator port
management.port = 9001
#HTTPS port
server.port=8443
#HTTP port
server.port.http=8080
#Enable SSL
server.ssl.enabled=true
...
Issue can be reproduced with Spring Boot 1.3.5 project configured with the above POM, application.properties and HttpSecurity & Application classes.
Upvotes: 1
Views: 1202
Reputation: 1
The solution this problem can be found here:
https://github.com/spring-projects/spring-boot/issues/6193
and creating a separate class extending TomcatEmbeddedServletContainerFactory and in that class have a public constructor that class super. The class extending TomcatEmbeddedServletContainerFactory can't be an inner class, it must be in it's own file and public in the package, otherwise the error will not go away.
Upvotes: 0
Reputation: 575
The usage of spring-boot-starter-actuator dependency together with management.port
being defined in application.properties
causes starting the embedded tomcat container to fail.
Removing the management.port
property definition from application.properties
makes the application to start up again.
It is worth noting that while removing the property fixed the issue it's not clear why.
Upvotes: 1