spring-boot property exception while externalizing datasource properties and using actuator

StackOverflow https://stackoverflow.com/questions/22870381

  •  27-06-2023
  •  | 
  •  

Question

Im creating a small application using spring-boot + gorm + sqlserver datasource (very similar to Tim Yates' https://github.com/timyates/data-gorm-mysql/).

My datasource properties are in application.properties:

dbDriverClassName=...
dbUsername=...

My build.gradle has

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

It works fine. But when I add the actuator to build.gradle, I get errors:

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

UPDATE (full stacktrace)

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

What am I missing? Thanks!

Was it helpful?

Solution

Solution:

I changed the build.gradle line from RC1 to RC2 and there is no error now (tested switching back to RC1 to confirm error, and back to RC2 - no error).

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

@Dave, thanks for the tip. But why do you say there is no reason to use custom DataSource, is there a better way?

I should have looked at repo.spring.io for latest version, but the stacktrace made me think it was an issue with actuator environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top