2

Spring 4 supports bean configuration using Groovy. You can define your beans using beans closure and it looks cleaner than xml. Moreover you can add flexible logic because it is a Groovy script.

My question is:

Is it possible to make IntelliJ IDEA understand such bean declarations? The problem is that when I use @Autowired, IDE says:

Could not autowire

Because it does not understand Groovy beans.

And by the way is it a good approach to use Groovy configuration for Spring? I did not notice people use it much in their projects even though i found them more convenient than XML.

Hamid Rouhani
  • 2,309
  • 2
  • 31
  • 45
Kirill
  • 6,762
  • 4
  • 51
  • 81

1 Answers1

0

I use Groovy beans with IntelliJ. It seems to work perfectly. I'm not sure what I've done configuration wise with Idea, but I do not get the error you are seeing.

We mix Groovy/Java DSL with some XML across our projects. We switched to the Groovy/Java DSL to get away from XML configurations. We started with all XML and are migrating to Groovy/Java DSL.

The only issue we've seen with Groovy is the lack of typing sometimes makes writing unit tests laborious.

IntelliJ IDEA 2016.1.3 Build #IU-145.1617, built on June 3, 2016 JRE: 1.8.0_76-release-b198 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

user54554
  • 1
  • 1
  • Can you please upload a simple project for me with .ipr and .idea files? – Kirill Jun 24 '16 at 13:28
  • Sorry, we are not using the Groovy Beans syntax to configure beans. We use groovy, but with the @Bean annotation. @Bean(name = "watch-file") RouteBuilder watchFile(@Value("${watched}") final String directory) { return new RouteBuilder() { @Override public void configure() throws Exception { logger.debug("watching {}", directory); from(String.format("file:%s?delete=true", directory)).to("activemq:queue:sync"); } }; ``` – user54554 Sep 29 '16 at 20:09