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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:38:36+00:00 2026-06-10T12:38:36+00:00

I am working under a spring mvc3 application. And I meet some problem when

  • 0

I am working under a spring mvc3 application.

And I meet some problem when I want to do some unit test for the Dao component.

This is my application structure in eclipse:

application
    build
        classes
    src
        org.....
    res
        jdbc.properties
        log4j.properties
    www
        resources
            css
            js
        WEB-INF
            mybatis
                config.xml
            view
            spring
                servlet-context.xml
                spring-contex.xml
                spring-dao.xml
            web.xml

servlet-context.xml:

<!-- web related config omitted -->
    <import resource="spring-context.xml" />
    <import resource="spring-dao.xml" />

spring-context.xml:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">.......</bean>

<context:property-placeholder location="classpath*:jdbc.properties" />

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="/WEB-INF/mybatis/config.xml" />
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

spring-dao.xml:

<bean id="postDao" class="com.king.dao.PostDao" />

And this is my PostDao class:

public class PostDao extends SqlSessionDaoSupport{
    public Post query(int id) {
        return getSqlSession().selectOne("com.king.model.PostMapper.selectById", id);
    }
}

The above configuration works well in the servlet container.

However when I want to test the PostDao without in the servlet environment,I meet some problems.

I tried this:

public static main(String[] args){
    ApplicationContext ctx = new ClassPathXmlApplicationContext("E:/application/www/WEB-INF/spring/servlet-context.xml");
    PostDao pd = (PostDao) ctx.getBean("postDao");
    Post p = pd.query(9);
}

Then I get the error, the “mybatis/config.xml” can not be founded.

I know this is caused by the different running environment.

In servlet context,spring will find the “/WEB-INF/mybatis/config.xml”,but when in a java application,it can not find it.

So I wonder how can I make my testing work?

  • 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-10T12:38:37+00:00Added an answer on June 10, 2026 at 12:38 pm

    Do you mean unit or integration testing? If so, I’d recommend using the Spring Test module – it allows you to define a specific test context where you can provide real or mocked implementations of the relevant beans. It integrates well with JUnit and provides a lot of the scaffolding you need to successfully run tests within a Spring environment.

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

Sidebar

Related Questions

I am working on some ListView I want to display a Button under it
I'm trying to get a MVC3 application working under mono, and everything was going
i am new in programming under linux and trying to get working this code:
I'm working on a project and trying to render some images sitting under the
I am working on splitting an MVC3 Application into two Areas. The existing application
I am working on a spring project. I use ant to deploy application and
I am developing a web application with spring mvc on eclipce under linux. What
While working on a Java application under Mac OS X (Lion, 10.7.2, Java version
I am working on a Spring MVC application in which I have recently been
I am currently working on some monitoring tool using aspectj. Because this tool should

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.