[Spring] Meta annotations and @Autowired.

I have several  meta annotations like the following:

 
@ContextConfiguration(locations = {"classpath:/META-INF/spring/application.xml"})
@Transactional
@Retention
(RUNTIME)
@Target(TYPE)
public @interface JpaRepositoryTest {}

used in tests like this:

 
@JpaRepositoryTest
@RunWith(SpringJUnit4ClassRunner.class)
public class FooRepositoryTest {
    @Autowired FooRepository repository;

    @Test
    public void test
() { ... }
}

Now, the test runs fine, however IntellIJ marks @Autowired dependency as "Autowired members must be defined in a valid spring bean" (it disappears if I move @ContextConfiguration to FooRepositoryTest).
Is there some sort of configuration to make IntelliJ see the spring context from composite annotation or this feature is simply not supported?

6 comments
Comment actions Permalink

It should work in IntelliJ IDEA 15.x

0
Comment actions Permalink

Well, it does not... I guess it's a bug then.

0
Comment actions Permalink

Any updates about this problem? I'm facing a similar issue. 

 

I have the following meta annotation:

 

@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@SpringApplicationConfiguration(AppBootstrap.class)
@WebIntegrationTest
@ActiveProfiles("test")
public @interface AppWebIntegrationTest {
String[] value() default {};
}
The class I use the annotation:
@RunWith(SpringJUnit4ClassRunner.class)
@AppWebIntegrationTest
public class DraftResourceIntegrationTest {

@Autowired
private ObjectMapper jacksonObjectMapper;

@Autowired
private DraftRepository draftRepository;

}

The tests runs fine but the IDE doesn't recognize the @Autowired objects and I get the following message:



"Could not autowire. No beans of 'DraftRepository' type found. less... (⌘F1)
Checks autowiring problems in a bean class."

 

0
Comment actions Permalink

Is there any work in progress for this subject ? I'm still having the same problem in 2017.3 : tests run fine but intellij doesn't recognize the auto-wired beans.

0
Comment actions Permalink

Please create an issue on YouTrack attaching sample project example: http://youtrack.jetbrains.com/issues/IDEA .

0

Please sign in to leave a comment.