Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register groovy bean in spring java config

I have this xml config

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:lang="http://www.springframework.org/schema/lang"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">

    <lang:groovy id="foo" script-source="${groovyBeanLocation}"/>
</beans>

I imported this config in my ApplicationConfig, but do not want to mix several types of configurations (java and xml).

How can I make a given configuration using java?

like image 411
Sem Grozovski Avatar asked Nov 10 '22 19:11

Sem Grozovski


1 Answers

If you're using a Groovy class as a Spring bean, you don't need the <lang:groovy> tag at all. Just deploy your compiled class as though it was Java, and it should just work as long as you include the groovy-all jar file as a project dependency.

The <lang:groovy> tag with a script-source is for "refreshable" beans. That's where you deploy the source code (rather than the compiled version), and Spring detects changes and recompiles for you. It's how you can update code in a running application, which is cool but pretty rare.

If all you want to do is write your implementation classes in Groovy, just compile them as usual and add them to the JavaConfig files the way you would any other bean. It's all bytecodes to Spring.

like image 169
kousen Avatar answered Nov 15 '22 06:11

kousen