I've create a small project to import data from a CSV into Neo4j. I started by creating a test but when it runs my ImportService class, it is unable to autowire the Neo4jTemplate. I found this thread (http://stackoverflow.com/questions/1...spring-project) which is similar to mine but I'm not using these old versions. Any idea why the template is not getting autowired so I can save to Neo4j?
Here's what I have
pom.xml:
Here is my applicationContext.xml (under src/main/resources):Code:<properties> <target.jdk>1.7</target.jdk> <spring.data.version>2.2.0.RELEASE</spring.data.version> <spring.version>3.1.4.RELEASE</spring.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-neo4j</artifactId> <version>${spring.data.version}</version> </dependency> <dependency> <groupId>net.sourceforge.javacsv</groupId> <artifactId>javacsv</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.2.1.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> </dependencies>
Here is my test:Code:<context:annotation-config/> <context:spring-configured/> <context:component-scan base-package="com.qualcomm.ea.ssat.poc.neo4j"/> <tx:annotation-driven mode="proxy"/> <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown"> <constructor-arg index="0" value="target/config-test"/> </bean> <neo4j:config graphDatabaseService="graphDatabaseService"/>
Here's my ImportService:Code:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:**/applicationContext.xml"}) public class ImportServiceTest { private ImportService importer = new ImportService(); @Test public void test() { CsvReader stationsFile = null; try { stationsFile = new CsvReader("C:\\dev\\spring-neo4j\\src\\main\\resources\\community_follows.csv"); stationsFile.readHeaders(); importer.importCommunities(stationsFile); } catch (Exception e) { e.printStackTrace(); } finally { stationsFile.close(); } } }
Code:@Service public class ImportService { @Autowired private Neo4jTemplate template; private Logger log = LoggerFactory.getLogger(ImportService.class); @Transactional public void importCommunities(CsvReader communityFile) throws IOException, ParseException { DateFormat dt = new SimpleDateFormat("dd-MMM-yy"); while (communityFile.readRecord()) { //CREATED,LAST_MODIFIED,GROUPID,COMMUNITY,DISPLAYNAME,FOLLOWER,FIRSTNAME,LASTNAME,DESCRIPTION String comm = communityFile.get(3); int id = Integer.parseInt(communityFile.get(2)); Date created = dt.parse(communityFile.get(0)); Date modified = dt.parse(communityFile.get(1)); String dname = communityFile.get(4); String description = communityFile.get(8); Community community = new Community(id, comm, dname, created, modified, description); template.save(community); // <<<<<<<<< Template is NULL } } }


Reply With Quote
