• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassPathXmlApplicationContext wildcard problem

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

my application currently consists of 2 spring context xml files, which are to be loaded via the ClassPathXmlApplicationContext.

The application is set up with maven and the context files are located under resources/spring/

This is how I create the context



This, however, only loads the services-context.xml which is located in the services project, but fails to load the database-context.xml (located in the database project).

If i turn the creation into

it does load the database config.

Why does it fail to load it when I use only wildcards?


Thank's for your help
 
Atul Kotwale
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand the problem. Please provide your maven project structure, it would really helpful understand the problem. Also please let us know which version of spring you are using. I checked the java doc(spring version 2.0) for ClassPathXmlApplicationContextclass and found that there is no constructor which takes two string argument. As you stated in your problem.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for your reply. I am currently trying to fix the problem, but no luck so far.

This is the (simplified) project structure.

Maven Projects:
- configuration
- database (depends on configuration)
- services (depends on database and on configuration)

in the source/main/resources folder, the database and services projects have a spring folder which contains the files services-context.xml and database-context.xml.

the configuration project contains a class that holds the application context. In essence, is encapsulates this:




Now, I solely run a main method in the database project and trigger the application context to initialize, I expect it to find the database-context.xml, and in fact it does.

When I run a main method in the services project and trigger the app context to initialize, I expect it to find the database-context.xml and the services-context.xml. As the services project depends on the database project, this shouldn't be a problem. However, it ends up finding the services-context.xml but not the database-context.xml.

I have checked the class path, the database-context.xml is included, but spring won't consider it.

Hope that helps to describe the problem.

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian

Have you tried loading the files this way:


 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, this works fine. but it's not what I want.

What I would like is all context files that are located in any project under spring/*-context.xml to be part of the application context, without having to add them to the list of context files.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you will be able to use wildcards here. The constructor you are using takes an array of Strings but each String must point to a single file.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, okay.

I thought that the ClassPathAppContext scans the class path to find all files that match the pattern.

It works id I do the following.

in the services-context.xml




That works and is acceptable I guess, even though the scanning variant would be more elegant.

There has to be a way to get this working, after all all those frameworks scan projects for spring files.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I have found a solution to get it working.


Here is how:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic