SSL Certifictae Setup
JeecgBoot uses a custom configuration for TomcatServletWebServerFactory, which requires specific handling when enabling HTTPS. This guide covers the complete setup process.
First, place your SSL certificate (JKS format) into the src/main/resources directory.
Application Configuration
Add the SSL certificate configuration to your application properties or YAML file:
server:
ssl:
key-store: classpath:your-domain.com.jks
key-store-password: your_password
key-store-type: JKS
The recommended approach is to use port 443 for HTTPS connections.
Maven Build Configuration
Configure the Maven resource plugin to properly include the certificate file while filtering other resources:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>your-domain.com.jks</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>your-domain.com.jks</include>
</includes>
</resource>
</resources>
</build>
Tomcat Factory Configuration
When encountering startup failures related to TomcatServletWebServerFactory, create or modify a configuration class to handle these issues:
@Configuration
public class TomcatFactoryConfig {
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
factory.addConnectorCustomizers(connector -> {
connector.setProperty("relaxedPathChars", "[]{}");
connector.setProperty("relaxedQueryChars", "[]{}");
});
return factory;
}
private Connector createHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setSecure(false);
connector.setPort(8080);
return connector;
}
}
The createHttpConnector() method demonstrates how to configure an HTTP connector that redirects to HTTPS. When needed, uncomment the method call and set redirectPort to 443 for automatic HTTP to HTTPS redirection.
After applying these configurations, the application should start successfully with HTTPS support enabled.