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

  • Home
  • SEARCH
  • 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 9150743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:39:06+00:00 2026-06-17T11:39:06+00:00

I have a Maven web project where I want to execute some JUnit integration

  • 0

I have a Maven web project where I want to execute some JUnit integration tests. To achieve that, I want to load the applicationContext.xml file to obtain the Spring injected beans. Also my application context files are located into src/main/resources/app_context, but when executing Maven’s lifecycle, it’s locating them into WEB-INF/classes/application_context, so I’m able to access them through the classpath.

<resource>
    <directory>src/main/resources/appcontext</directory>
    <targetPath>${basedir}/src/main/webapp/WEB-INF/classes/application_context</targetPath>
    <filtering>true</filtering>
    <includes>
        <include>*/**</include>
    </includes>
</resource>

I have tried to access that context in some ways, but without succeeding. I’m also putting them into Maven’s target test directory in that way:

<testResources>
    <testResource>
        <directory>
                src/main/resources/appcontext
            </directory>
        <targetPath>${basedir}/src/main/webapp/WEB-INF/classes/application_context</targetPath>
    </testResource>
</testResources>

This is a piece of my Test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:**/applicationContext.xml" })
@Transactional
public class SystemTest {

    @Autowired
    ApplicationContext applicationContext;

    @Test
    public void initializeSystemTest() {
            //Test code

And that’s how I have access to the rest of the application context files from my main one:

<?xml version="1.0" encoding="ISO-8859-15"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <import resource="classpath:application_context/ApplicationContext*.xml" />
    <context:annotation-config />
    <!--========== Spring Data Source ========== -->
    <!--Bean stuff-->

Basically I want to have only a copy of each one of the applicationContext files stored in src/main/resources and let Maven copy them for test and execution scopes. However my test classes are unable to find and load them. What I have to do?

  • 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-17T11:39:07+00:00Added an answer on June 17, 2026 at 11:39 am

    Assuming your applicationContext.xml is in src/main/resources/appcontext, Maven will realocate it in WEB-INF/classes/appcontext by default. It’s not necessary to assign a new path for that resource.

    You should be able to find the context file in your test with:

    @ContextConfiguration(locations={"/appcontext/applicationContext.xml"})
    

    You shouldn’t need additional Maven settings for this.

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

Sidebar

Related Questions

I have a web application Maven project, and I want to customize the web.xml
I have a Maven based Spring-WS client project that I want to package as
I have a maven project that is generating a .war file. I want to
I have a .jar that I want included in my IDEA web application project
I have a maven web project that imported into eclipse. I have another maven
Im developing a web application in a maven project. I also have a second
Let's say I have two maven profiles for running projects web tests: 1. first
I have Maven project with Hibernate and Spring framework. I want Hibernate to create
I have a maven project that contains a certain api I need to use
I have a large Java Web Application project using Maven and I need to

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.