Hi all,
As a fun learning experience I am attempting to move an application's
Spring configuration from XML to Groovy. I need to create a bean for a
Groovy class that is annotated with @Immutable.
Let's say my class is this:
@Immutable
class MyImmutableClass {
String someString
String otherString
String anotherString
}
And I attempt to create a bean like so:
beans {
myImmutableClass(
MyImmutableClass,
someString: 'some',
otherString: 'other',
anotherString: 'another'
)
}
It fails:
Invalid property 'someString' of bean class [MyImmutableClass]: Bean
property 'someString' is not writable or has an invalid setter method. Does
the parameter type of the setter match the return type of the getter?
I can do the following, but I then lose the parameter name information that
tells me which fields are set to which values:
beans {
myImmutableClass(
MyImmutableClass,
'some',
'other',
'another'
)
}
I can also remove the @Immutable annotation from the class. But let's
assume this class comes from somewhere else and I cannot modify it.
So what are my options here that combine not modifying the @Immutable class
and keeping the parameter names? I know I can combine Groovy and XML
configuration and define the bean in XML and then use importBeans in my
Groovy code, but is there something I can do that is purely Groovy?
I found this issue, which describes my problem:
https://issues.apache.org/jira/browse/GROOVY-7078
Thanks,
Rick