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 5934945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:11:06+00:00 2026-05-22T15:11:06+00:00

I have web application on spring mvc and maven. When I execute mvn clean

  • 0

I have web application on spring mvc and maven.
When I execute “mvn clean install” I got nullpointerexception from some uni-test.
It’s happens because one of resource is null, but why ?

Uni-test:

package myapp.services.impl

....

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:META-INF/spring/applicationContext.xml"})
@TransactionConfiguration
public class MyServiceImplTest {

    @Resource
    private MyService myService;

    @Transactional
    @Test
    public void someTest() {
        SomeEntity entity = new SomeEntity();
        myService.createSomething(entity);  // THROW - NullPointerException, myService is NULL
        ...
    }
}

surefire plugin in pom.xml:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.3</version>
            <configuration>
                <systemProperties>
                    <property>
                        <name>myapp.env</name>
                        <value>test</value>
                    </property>
                </systemProperties>
                <junitArtifactName>org.junit:com.springsource.org.junit</junitArtifactName>
            </configuration>
        </plugin>

And applicationContext.xml:

...
<context:component-scan base-package="myapp.services,myapp.services.impl"/>

<context:property-placeholder location="classpath*:META-INF/spring/common_${myapp.env}.properties"
                              system-properties-mode="OVERRIDE"
                              ignore-resource-not-found="true"/>
....

PS: When I execute this test in eclipse Run as JUnit Test – execute is fine without exception

Stack-trace after surefire report:


Test set: myapp.services.impl.MyServiceImplTest

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.115 sec <<< FAILURE!
myapp.services.impl.MyServiceImplTest.someTest() Time elapsed: 1.068 sec <<< FAILURE!
java.lang.NullPointerException
at myapp.services.impl.MyServiceImplTest.someTest(MyServiceImplTest.java:42)

MAVEN OUTPUT:

...
[INFO] --- maven-surefire-plugin:2.4.3:test (default-test) @ mywebapp ---
[INFO] Surefire report directory: /home/xxx/Work/mywebapp/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running myapp.services.impl.MyServiceImplTest
log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
log4j:WARN No such property [maxBackupIndex] in     org.apache.log4j.DailyRollingFileAppender.
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.919 sec <<< FAILURE!


Results :

Failed tests: 
  myapp.services.impl.MyServiceImplTest.someTest()

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 41.465s
[INFO] Finished at: Mon May 09 00:05:06 MSD 2011
[INFO] Final Memory: 26M/70M
...
  • 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-05-22T15:11:06+00:00Added an answer on May 22, 2026 at 3:11 pm

    Just a thought but…

    You say you’ve placed applicationContext.xml in the test/resources folder – have you recreated the directory structure you define within that directory? I.e. test/resources/META-INF/spring/applicationcontext.xml? If not, then the applicationcontext will appear in test-classes/ and won’t be found according to the classpath location you’ve defined… If it’s just in test/resources, change your @ContextConfiguration annotation to

    @ContextConfiguration(locations = {"classpath:applicationContext.xml"})`
    

    `

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

Sidebar

Related Questions

I am using Spring MVC to build my web application, and I have a
we have a J2EE web application usig Spring MVC. We have a new requirement
So I've got a simple web application using Spring MVC + Hibernate and am
I'm trying to make this 2-player web game application using Spring MVC. I have
I have a web application using JPA and JTA with Spring. I would like
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests
I have a web application that needs to take a file upload from the
I have an existing, fully functional Spring web application based on Spring 2.5.6 -
We have a legacy web application (not Spring based) and are looking for best
I'm attempting to create a Spring application (NOT web application) to perform some simple

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.