Reputation: 2385
I have the following in my web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
I have 2 files:
When deploying the app, I get a
No matching bean of type [AServiceBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
Seems like the applicationContext-service.xml is not found. If I copy it next to the web.xml, it works fine. I can't figure out why this happens.
The server is a Tomcat 6.
Any help is appreciated. Thanks.
EDIT
For clarification: if I use
<param-value>
classpath:applicationContext-web.xml,
classpath:applicationContext-service.xml
</param-value>
the app deploys without any issue, so it's just a matter of finding (or not finding) the applicationContext-service.xml
Upvotes: 2
Views: 3073
Reputation: 14548
You need to place your config files into the classpath.
WEB-INF/classess is the directory you need to place your configuration files
classpath:applicationContext-*.xml will then work
or sth similar to this to keep them in one place
WEB-INF/classes/spring
classpath:spring/applicationContext-*.xml
applicationContext-service.xml : You dont need to copy this one if it is already in the jar file
Sample main-config.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<import resource="classpath:spring/config1.xml" />
<import resource="classpath:spring/config2.xml" />
.
.
<import resource="classpath:spring/configN.xml" />
</beans>
Upvotes: 1
Reputation: 28951
Try to use classpath*:applicationContext-*.xml
(there is asterisk before the colon).
However it may not work, e.g. JBoss has problems, to make it work you need use some special class loader from jboss.
Also, there are some problems using patterns in root.
Anyway I would recommend avoid patterns, better to make an applicationContext.xml
with two explicit import
statements.
Upvotes: 3