Ram
Ram

Reputation: 2387

Idea 12, How do I indicate some spring files are used only for Tests

I have multiple spring config files. Few are for testing.

Throughout the code base Idea12 has highlighted all Autowired beans as "There is more than one bean of XXX type".

How do I configure IDEA so that it correctly identifies the instances to be used in testing and in production?

Upvotes: 7

Views: 2013

Answers (4)

Felix Reckers
Felix Reckers

Reputation: 1292

I deactivated the warning through Settings -> Inspections -> Spring Model -> Autowiring for Bean Class. Hope this issue will be fixed soon. Im using version 12.1.4 of IntelliJ

Upvotes: 0

bsmk
bsmk

Reputation: 1347

I don't think that this issue is fixed in 12.1.4. Not perfect fix is to right click on spring config file in test folder and mark it as plain text.

Upvotes: 0

vdshb
vdshb

Reputation: 1999

This issue also shows up when I try to annotate one class with two or more annotations, like that:

@Service
@Repository
public class Foo {...}

@Component
public class AnotherFoo {
    @Inject
    Foo foo; // Here is error in IDEA, in spite of Spring takes it normally.
}

So clean from unnecessary annotations(@Service in this example) can help from annoying warnings.

Upvotes: 0

Alex Vayda
Alex Vayda

Reputation: 6494

It's supposed to be fixed in the next update. But meantime just go the Project Structure -> Facets -> Spring and remove some of the application context configurations that include ones already defined.

For instance, I have 2 modules in my project: Core (jar) and Webapp (war) which depends on the Core. When both are included into the Spring facet in IDEA the beans defined in the Core application context are seen twice by IDE: 1st time directly from Core application context and 2nd time from Webapp context which includes Core context. Since Core module beans are already visible in Web module the Spring facet for Core can be removed and the issue will be fixed.

Upvotes: 3

Related Questions