我有一个Spring Boot应用程序,它将遗留Web服务公开为RESTful API.相关代码将是:
@Configuration @PropertySource("classpath:foo.properties") @ComponentScan("foo.bar") @EnableAutoConfiguration public class Application { @Autowired private Environment env; @Bean public EmbeddedServletContainerCustomizer containerCustomizer() throws FileNotFoundException { final String absoluteKeystoreFile = ResourceUtils.getFile(env.getProperty("security.settings.keystore.path")).getAbsolutePath(); System.out.println("PATH: " + absoluteKeystoreFile); return new EmbeddedServletContainerCustomizer() { @Override public void customize( ConfigurableEmbeddedServletContainer factory) { if (factory instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) factory; containerFactory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override public void customize(Connector connector) { connector.setPort(Integer.parseInt(env.getProperty("server.settings.port"))); connector.setDomain(env.getProperty("server.settings.address")); connector.setSecure(true); connector.setScheme("https"); Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler(); proto.setSSLEnabled(true); proto.setKeystoreFile(absoluteKeystoreFile); proto.setKeystorePass(env.getProperty("security.settings.keystore.pass")); proto.setKeystoreType(env.getProperty("security.settings.keystore.type")); proto.setKeyAlias(env.getProperty("security.settings.key.alias")); } }); } } }; } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
在我的POM中:
org.springframework.boot spring-boot-starter-parent ${springboot-version} pom import org.springframework spring-framework-bom ${spring-version} pom import org.springframework spring-context org.springframework.boot spring-boot-starter-web 4.1.1.RELEASE 1.1.8.RELEASE
它曾经工作正常,但现在我收到此错误:
2014-11-04 12:18:10.638 WARN 664 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties': Could not bind properties; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'settings[port]' of bean class [org.springframework.boot.autoconfigure.web.ServerProperties]: Cannot access indexed value in property referenced in indexed property path 'settings[port]'; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'settings[port]' of bean class [org.springframework.boot.autoconfigure.web.ServerProperties]: Bean property 'settings[port]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
我创建了一个示例Spring Boot应用程序,它在那里工作正常.我该如何进一步排除故障?
你不能拥有server.settings.*
外部属性(除非你采取一些措施来排除它试图绑定的东西,或者将属性分离出来Environment
).Spring Boot绑定server.*
到ServerProperties
它并且没有"settings"属性.