• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassPathXmlApplicationContext wildcard problem

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I have found a solution to get it working.


Here is how:

 
reply
    Bookmark Topic Watch Topic
  • New Topic