Я пытаюсь настроить встроенный Spring-Boot Tomcat, я создал класс настройщика, как показано здесь
@Configuration
@PropertySource("classpath:configure_springboot.properties")
public class EmbeddedTomcatConfiguration {
private static final String HTTP_PROTOCOL = "HTTP/1.1";
private static final String URI_ENCODING = "UTF-8";
@Value("${server.connection-timeout}")
int serverConnectionTimeout;
@Value("${tomcat.http.port}")
int httpPort;
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
return container -> container.addAdditionalTomcatConnectors(getHTTPConnector());
}
private Connector getHTTPConnector() {
Connector httpConnector = new Connector(HTTP_PROTOCOL);
httpConnector.setPort(httpPort);
((AbstractProtocol) httpConnector.getProtocolHandler()).setConnectionTimeout(serverConnectionTimeout);
httpConnector.setURIEncoding(URI_ENCODING);
return httpConnector;
}
}
Чтобы проверить мои настройки, я создаю TomcatServletWebServerFactory здесь
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {EmbeddedTomcatConfiguration.class, ServletWebServerFactoryAutoConfiguration.class })
public class EmbeddedTomcatConfigurationTest {
@Autowired
TomcatServletWebServerFactory tomcatServletWebServerFactory;
@Test
public void tomcatHttpConnector() {
assertNotNull(tomcatServletWebServerFactory);
}
}
, но мой тест не пройден с ошибкой
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.springboot.configure.EmbeddedTomcatConfigurationTest': Unsatisfied dependency expressed through field 'tomcatServletWebServerFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Я пробовал это в течение последних трех дней, может кто-нибудь подсказать мне, что мне здесь не хватает?