I am building a new application that configures spring through a java config rather than xml. This app is dependent on a module that uses the xml style config. When I try and launch my app, I get the following error:
No qualifying bean of type [com.myModule.myServiceImp] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
This bean should be declared in the module's applicationContext.xml. What is the proper way to handle this? I tried simply adding it as I would if I was stringing application contexts together in the app's web.xml:
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:com/myModule/appbase-context.xml com.myApp.AppConfig </param-value> </context-param>
But I still got the same error. What is the proper way to do this?
Yes, you can use XML, annotations, or a mix.
Spring allows you to configure your beans using Java and XML.
XML configuration is still officially supported by Spring.
In your configuration class, you can import xml configuration via the @ImportResource
annotation.
Something like this:
@Configuration @ImportResource({"classpath:appbase-context.xml"}) public class AppConfig { // @Bean definitions here... }
Remember, when you are using Spring's Java Configuration, you need to specify an additional context-param
that says the class to use for your application context:
<context-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </context-param>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With