Я использую Spring boot 2.0.4
.Я хочу настроить автоматическое перенаправление с http на https для всех шаблонов URL.Я добавляю в application.yml следующие строки:
server:
ssl:
enabled: true
key-alias: tomcat
key-store: "classpath:tomcat.keystore"
key-store-type: jks
key-store-password: 123456
key-password: 123456
И я создал bean-компонент:
@Bean
public TomcatServletWebServerFactory httpsRedirectConfig() {
return new TomcatServletWebServerFactory () {
@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);
}
};
}
Но, когда я запускаю свое приложение, у меня появляется ошибка:
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans : tomcatServletWebServerFactory,httpsRedirectConfig
Что не так?Как я могу это исправить?Thx.