2

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:

  • applicationContext-web.xml in the WEB-INF next to the web.xml
  • applicationContext-service.xml in the myapp-service.jar

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

1
  • Do you have component-scan configured ? Commented Dec 6, 2011 at 14:49

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Nope. classpath*... doesn't work. Tried on Tomcat 7 too. No luck.
Thanks. That's the conclusion I arrived to, too (avoiding wildcard characters). I'll look into the import idea - never used that before, maybe it's time to give it a try.
1

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> 

5 Comments

You did not follow my question. The config files ARE in the classpath. And the one that's not found is exactly the -service one, that is in a JAR.
yes, my bad. Whereabouts the service xml is in your jar file? is it at the root of jar or in some directory?
It's in the root of the JAR. I saw in the Spring docs there could be problems with wildcards. In the end I will probably have to stick to a list of context files names instead of using wildcards, especially since this app has to be able to run on a lot of servers and versions.
You can import all the config files in one and pass that in the web.xml
see above, i have updated with some sample file importing other config files.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.