No bean named "..." and Spring @Resource annotation
I use @Resource to comment out the bean classes, @Autowired for autowire dependencies, and in my Spring config file do the following:
context: component-scan base-package = "package1, package2"
tx: annotation-driven
So it works great (tested). Spring scans package1, package2, classes with @Resource annotation and then I can get them with getBean () IF TESTED FROM CONSOLE APPLICATION [say with main () function]. In the meantime, there is no need to worry about it. ”
But when I try the following approach (use Spring in container managed environment = with Tomcat):
<context-param>
<param-name> contextConfigLocation </param-name>
<param-value> classpath *: beans.xml </param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.request.RequestContextListener </listener-class>
</listener>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
compile a jar with all bean classes and put this jar in WEB-INF / lib
what i see? I cannot getBean () any of these @Resource annotated beans!
Spring just won't find them.
However, I can getBean () beans that are explicitly present in beans.xml.
Where is the problem?
a source to share
Missing <context:annotation-config/>
?
<context:annotation-config/>
<context:component-scan base-package="package1"/>
<context:component-scan base-package="package2"/>
<tx:annotation-driven transaction-manager="transactionManager" />
or
<context:annotation-config/>
<context:component-scan base-package="package1, package2"/>
<tx:annotation-driven transaction-manager="transactionManager" />
a source to share