Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails Spring DSL Not Setting String Properties

Tags:

spring

grails

2 simple String properties on my Service:

class MyService {

    static transactional = false

    def uri1
    def uri2
}

resources.groovy:

beans = {
    myService(com.myapp.MyService) {
        uri1 = 'http://my.endpoint1.com'
        uri2 = 'http://my.endpoint2.com'
    }
}

And.. Both properties remain null. Seems simple and obvious enough, but little to go on and I seem to be explicitly following the doc and some posts I've found.. Any ideas? Thanks.

I've tried typing the properties as String, def, static String.. nothing helps. I've tried using bean -> in the properties closure and bean.str1 etc... nothing helps.

UPDATE: The goal is simply to set these string properties on the Service class via Spring. Yes, using Config.groovy is an option, but that requires an extra step of accessing the config.. which I find to be an unnecessary hoop to jump through in this case. After all, Spring is being used, so why not use it. In my case they happen to be URI's (updated example code).

See: http://grails.org/doc/1.0.x/guide/14.%20Grails%20and%20Spring.html 14.3, for example. Where driverClassName = "org.hsqldb.jdbcDriver" is set on a dataSource registration. I tried adding java-style setters and getters to the Service class, still null

like image 933
Bobby Avatar asked Aug 12 '26 05:08

Bobby


1 Answers

You're not going nuts, this should work exactly as you think it should.

I've prepared an example project to confirm this over on github:

https://github.com/gid79/so-q8548146-spring-dsl

I prepared the example with grails 1.3.4, which just happened to be the version I have installed locally, it's been a little while since I used it.

It is possible that you have stumbled onto a bug in the version you are using, your references are to 1.0.x documentation, which version are you using?

like image 104
Gareth Davis Avatar answered Aug 14 '26 18:08

Gareth Davis