java - Spring's component-scan don't find class in external jar -
i'm new in spring, "autowired" class interface implement class in external jar.
this jar's code:
@component public class mongospring implements imongo { mongospring() throws unknownhostexception { system.out.println("mongo template builder"); } @required public void save() { system.out.println("mongo template save"); } }
the class interface:
@component public interface imongo { void save(); }
the class make autowire
@component public class core { @autowired public imongo db ; public void run () { log.info("core "); db.save(); }
the main class
public class mongoapp { private static applicationcontext context; public static void main(string[] args) throws exception { context = new classpathxmlapplicationcontext("path.xml"); core c = (core)context.getbean(core.class); c.run(); } }
the bean file:
<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" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package="org.spring.mongodb.example" /> </bean> </beans>
when run gives me following error:
exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'core': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: public org.spring.mongodb.example.imongo org.spring.mongodb.example.core.db; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no matching bean of type [org.spring.mongodb.example.imongo] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)}
[...]
what can do? i'm using spring 3.2.0 sts
i have removed @component interface , @require doesn't change. jar file in classpath , package correct. thank you
Comments
Post a Comment