diff --git a/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java index 841fe1520..e050e7f1b 100644 --- a/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java +++ b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java @@ -23,6 +23,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.neo4j.helpers.Pair; import org.springframework.data.graph.neo4j.server.SpringPluginInitializer; import javax.ws.rs.POST; @@ -36,7 +37,7 @@ public class SpringPluginInitializerTest extends SpringPluginInitializer impleme private LocalTestServer neoServer; public SpringPluginInitializerTest() { - super( new String[]{"ServerTest-context.xml"}, "testObject" ); + super( new String[]{"ServerTest-context.xml"}, Pair.of("testObject", TestInterface.class) ); } private static int touched = 0; @@ -50,21 +51,6 @@ public class SpringPluginInitializerTest extends SpringPluginInitializer impleme test.thisIsARecording(); } - @Test - public void shouldInjectInterface() throws Exception { - ClientResponse response = sendRequest( "testInterface" ); - - Assert.assertEquals( 204, response.getStatus() ); - Assert.assertEquals( 1, touched ); - } - - @Path( "/testConcrete" ) - @POST - @Produces( MediaType.APPLICATION_JSON ) - public void runThis( @Context SpringPluginInitializerTest test ) { - test.thisIsARecording(); - } - @Path( "/testNoContext" ) @POST @Produces( MediaType.APPLICATION_JSON ) @@ -84,6 +70,14 @@ public class SpringPluginInitializerTest extends SpringPluginInitializer impleme neoServer.stop(); } + @Test + public void shouldInjectInterface() throws Exception { + ClientResponse response = sendRequest( "testInterface" ); + + Assert.assertEquals( 204, response.getStatus() ); + Assert.assertEquals( 1, touched ); + } + @Test public void shouldWorkWithThirdPartyJaxrs() throws Exception { ClientResponse response = sendRequest( "testNoContext" ); @@ -91,15 +85,6 @@ public class SpringPluginInitializerTest extends SpringPluginInitializer impleme Assert.assertEquals( 204, response.getStatus() ); } - - @Test - public void shouldInjectConcreteClass() throws Exception { - ClientResponse response = sendRequest( "testConcrete" ); - - Assert.assertEquals( 204, response.getStatus() ); - Assert.assertEquals( 1, touched ); - } - private ClientResponse sendRequest( String method ) { return Client.create(). resource( "http://localhost:7473/test/" + method ). diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/server/SpringPluginInitializer.java b/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/server/SpringPluginInitializer.java index 4f85136b3..e792eae76 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/server/SpringPluginInitializer.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/server/SpringPluginInitializer.java @@ -18,13 +18,13 @@ package org.springframework.data.graph.neo4j.server; import org.apache.commons.configuration.Configuration; import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.helpers.Pair; import org.neo4j.server.plugins.Injectable; import org.neo4j.server.plugins.PluginLifecycle; import org.springframework.context.ApplicationContext; import java.util.ArrayList; import java.util.Collection; -import java.util.List; /** * Initializer to run Spring Data Graph based Server Plugins in a Neo4j REST-server. It takes the list of @@ -39,12 +39,12 @@ import java.util.List; * } * */ -public abstract class SpringPluginInitializer implements PluginLifecycle { +public abstract class SpringPluginInitializer implements PluginLifecycle { private String[] contextLocations; - private String[] exposedBeans; + private Pair>[] exposedBeans; protected ProvidedClassPathXmlApplicationContext ctx; - public SpringPluginInitializer( String[] contextLocations, String... exposedBeans ) { + public SpringPluginInitializer( String[] contextLocations, Pair>... exposedBeans) { this.contextLocations = contextLocations; this.exposedBeans = exposedBeans; } @@ -62,21 +62,9 @@ public abstract class SpringPluginInitializer implements PluginLifecycle { ctx = new ProvidedClassPathXmlApplicationContext( graphDatabaseService, contextLocations ); Collection> result = new ArrayList>( exposedBeans.length ); ProvidedClassPathXmlApplicationContext appCtx = SpringPluginInitializer.this.ctx; - for ( final String exposedBean : exposedBeans ) { - Class concreteType = ctx.getType( exposedBean ); - result.add( new SpringBeanInjectable( appCtx, exposedBean, concreteType ) ); - result.addAll( getInjectablesForInterfaces( appCtx, exposedBean, concreteType ) ); - } - return result; - } - - private List> getInjectablesForInterfaces( ProvidedClassPathXmlApplicationContext appCtx, - String exposedBean, - Class concreteType ) { - - ArrayList> result = new ArrayList>(); - for ( Class iface : concreteType.getInterfaces() ) { - result.add( new SpringBeanInjectable( appCtx, exposedBean, iface ) ); + for ( final Pair> exposedBean : exposedBeans ) { +// Class concreteType = ctx.getType( exposedBean ); + result.add( new SpringBeanInjectable( appCtx, exposedBean.first(), exposedBean.other() ) ); } return result; } diff --git a/src/docbkx/reference/neo4j-server.xml b/src/docbkx/reference/neo4j-server.xml index 73b3da923..d9f26aef1 100644 --- a/src/docbkx/reference/neo4j-server.xml +++ b/src/docbkx/reference/neo4j-server.xml @@ -39,16 +39,26 @@ org.neo4j.server.thirdparty_jaxrs_classes=com.example.mypackage=/my-context Running Spring Data Graph on the server is easy. You need to tell the server where to find the Spring Context - file, and which beans from it to expose: + file, and which beans from it to expose, using what type: + Now, your resources can be annotated with the beans they need, like this: + + The SpringPluginInitializer merges the graph database service with the spring configuration and registers the named beans as jersey Injectables. It is still necessary to list the initializer fully qualified class name in a