开发者

How does Spring's @Autowired work with interfaces that have no implementation?

I am working with SpringData's Neo4j graph DB hello-worlds example and I ran across the following code in WorldRepositoriesImpl.java...

@Autowired private WorldRepository worldRepository;

Furthermore, WorldRepository is defined as...

public interface WorldRepository extends MyWorldRepository, 
                                         GraphRepository<World>,
                                         NamedIndexRepository<World> 
{/* no method defined here */}

Now the odd p开发者_JAVA技巧art, no class that I can find actually implements WorldRepository.So, a few questions...

How is this possible? Where is this documented? Is there a way to make this a bit more explicit (less mysterious)?


Running the code with a debugger attached shows that the worldRepository instance wired up by Spring is a proxy object created at runtime.

Looking at the pom.xml and the dependencies included, it looks like the spring-neo4j library bundles in some Aspects that create this implementation class at runtime.

In other words, there is no implementation of this interface declared in the source code - but one is created at runtime with AspectJ and other tools.

How does Spring's @Autowired work with interfaces that have no implementation?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜