简体   繁体   中英

Annotating Groovy beans to load within Spring

Our application uses @Bean to define create beans and load them into the Spring context. We now need to externalize these, so as to enable the application to be configured without touching the java source code.

We wish to replace the @Bean 's with Groovy classes.

Is there a way to annotate a Groovy bean so that it will be picked up by Spring?

Note that we cannot simply reference each Groovy bean in the Spring XML, as we need to add and modify beans without touching the Spring code.

Thanks very much.

Use Spring config inheritance.

Move all shared code in a common "base" project that each individual / specific project depends on. Use Maven for this.

Create a common / base Spring config and put that into the "base" project. This config doesn't contain a definition for ProcessDefinition

In the specific project, create one bean which inherits from ProcessDefinition . Create a Spring config which imports the base config and define the single specific bean in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM