外部化数据源属性和使用执行器时的spring-boot属性异常

时间:2014-04-04 18:27:30

标签: gorm spring-boot

我使用spring-boot + gorm + sqlserver数据源创建一个小应用程序(非常类似于Tim Yates' https://github.com/timyates/data-gorm-mysql/)。

我的数据源属性位于application.properties中:

dbDriverClassName=...
dbUsername=...

我的build.gradle有

compile("org.springframework.boot:spring-boot-starter-web")
compile("org.grails:gorm-hibernate4-spring-boot:1.0.0.RC1")

工作正常。但是当我将执行器添加到build.gradle时,我会收到错误:

compile("org.springframework.boot:spring-boot-starter-actuator")

更新(完整堆栈跟踪)

thread "main"                                                                                                                                                                              org.springfra
mework.beans.factory.BeanCreationException: Error creating bean with name 'environmentEndpoint': Could not bind properties; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'dbUsername' of bean class [org.springframework.boot.actuate.endpoint.EnvironmentEndpoint]: Bean property 'dbUsername' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:321)
        at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:278)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)




                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
2014-04-05 08:40:09.661  INFO 8136 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)


        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
        at org.springframework.context..AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:619)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:880)
        at org.springframework.boot.SpringApplication$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
        at gov.texas.iph.IphApplication.main(IphApplication.groovy:25)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dbUsername' of bean class [org.springframework.boot.actuate.endpoint.EnvironmentEndpoint]: Bean property 'dbUsername' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
        at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
        at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:728)
        at org.springframework.validation.DataBinder.doBind(DataBinder.java:624)
        at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:84)
        at org.springframework.validation.DataBinder.bind(DataBinder.java:609)
        at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfiguratory.java:275)
        at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:225)
        at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:318)
        ... 21 more
:bootRun FAILED

我错过了什么? 谢谢!

1 个答案:

答案 0 :(得分:0)

解决方案:

我将build.gradle行从RC1更改为RC2并且现在没有错误(测试切换回RC1以确认错误,然后返回RC2 - 没有错误)。

compile("org.grails:gorm-hibernate4-spring-boot:1.0.0.RC2")

@Dave,谢谢你的提示。但是为什么你说没有理由使用自定义DataSource,有更好的方法吗?

我应该看一下repo.spring.io的最新版本,但堆栈跟踪让我觉得这是执行器环境的一个问题。