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?


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.


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.


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.

链接地址: http://www.djcxy.com/p/11602.html

上一篇: 在Tcl 8.5中打开/读取大文件的命令

下一篇: 想法12,我如何指示一些弹簧文件仅用于测试