Autofirm failed. No beans type Neo4jTemplate type

I am using IDEA IntelliJ 12.0.2.

My application is context.xml:

<?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:context="http://www.springframework.org/schema/context" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd"> <neo4j:config storeDirectory="../embeddedNeo4j"/> <context:spring-configured/> <context:annotation-config/> <context:component-scan base-package="models"/> </beans> 

My test class:

 import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.neo4j.support.Neo4jTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"/application-context.xml"}) @Transactional public class MyTest { @Autowired Neo4jTemplate template; //=> Could not autowire.No beans of Neo4jTemplate type found //my tests here } 

Am I missing some kind of configuration?

There seems to be an old problem with Intellij: http://www.markvandenbergh.com/archives/260/autowiring-spring-bean-in-intellij/

+7
source share
1 answer

This happens a lot in IntelliJ with Spring Data beans. IntelliJ does not parse examples from Spring data namespace configurations too well. As an example (in addition to yours), IntelliJ will not correctly validate the @Autowired or @Inject ed class, which extends Spring Data MongoRepository . As you noticed, this will not harm your application, but during development it is very annoying. Here is how you can suppress the "error":

 @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired Neo4jTemplate template; 

You can do the same by clicking the red light (error indicator when you hover over an item with a red underline), selecting Autowiring Verify Class Bean for Bean, and then finally Suppress Field. Or, if you want to suppress it for your class, select Suppress For Class.

+7
source

All Articles