Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:56:58+00:00 2026-06-03T13:56:58+00:00

When I run my application on tomcat the spring-context.xml file is located at /WEB-inf/spring-context.xml

  • 0

When I run my application on tomcat the spring-context.xml file is located at

/WEB-inf/spring-context.xml

This is ok. But running a junit test I have to supply it with the location of my spring-test-context.xml like this:

@ContextConfiguration(locations={"classpath:/spring-test-context.xml"})

The only way this works is if the file is located in

/src/spring-context.xml

How can I get my application to find my spring-context files in the same location? So that it works with junit testes and deployed on tomcat?

I tried this and it gave me alot of errors about not finding any beans, but it didn’t say it couldn’t find the file..

classpath:/WEB-INF/spring-test-context.xml
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:56:59+00:00Added an answer on June 3, 2026 at 1:56 pm

    As duffymo hinted at, the Spring TestContext Framework (TCF) assumes that string locations are in the classpath by default. For details, see the JavaDoc for ContextConfiguration.

    Note, however, that you can also specify resources in the file system with either an absolute or relative path using Spring’s resource abstraction (i.e., by using the “file:” prefix). You can find details on that in the JavaDoc for the modifyLocations() method in Spring’s AbstractContextLoader.

    So for example, if your XML configuration file is located in "src/main/webapp/WEB-INF/spring-config.xml" in your project folder, you could specify the location as a relative file system path as follows:

    @ContextConfiguration("file:src/main/webapp/WEB-INF/spring-config.xml")
    

    As an alternative, you could store your Spring configuration files in the classpath (e.g., src/main/resources) and then reference them via the classpath in your Spring MVC configuration — for example:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/spring-config.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    

    With this approach, your test configuration would simply look like this (note the leading slash that denotes that the resource is in the root of the classpath):

    @ContextConfiguration("/spring-config.xml")
    

    You might also find the Context configuration with XML resources section of the reference manual useful.

    Regards,

    Sam

    (author of the Spring TestContext Framework)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to run spring mvc application on tomcat(with this plugin http://mojo.codehaus.org/tomcat-maven-plugin/ )
If I follow spring and bitronix instructions and I run web application on tomcat,
We have a j2ee/spring/hibernate/tomcat web application already running on production. We are planning to
I'm trying to run my web application on tomcat v6, I was testing it
I run a Tomcat 7 web application on 2 locations; in one location there
I have a web application running in tomcat where I'm using a ThreadPool (Java
I have a web application that's based on Spring and the application contexts, applicationContext.xml
I have an JPA/Hibernate/Spring/Tomcat web application with second level data cache enabled for performance
I have a java web application wired using Spring on Tomcat. I need a
Right now whenever I run application It creates a file (file name specified in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.