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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:30:19+00:00 2026-06-11T20:30:19+00:00

Background /pom.xml … <properties> … <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver> <jdbc.url>jdbc:mysql://${database.host}/${database.name}</jdbc.url> <jdbc.user>${database.user}</jdbc.user> <jdbc.password>${database.password}</jdbc.password> … </properties> … <profiles> <profile>

  • 0

Background

/pom.xml

...
<properties>
    ...
    <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
    <jdbc.url>jdbc:mysql://${database.host}/${database.name}</jdbc.url>
    <jdbc.user>${database.user}</jdbc.user>
    <jdbc.password>${database.password}</jdbc.password>
    ...
</properties>
...
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            ...
            <database.name>database</database.name>
            <database.host>localhost</database.host>
            <database.user>root</database.user>
            <database.password></database.password>
            ...
        </properties>
    </profile>
</profiles>
...

/src/main/resources/database.properties

...
jdbc.driver=${jdbc.driver}
jdbc.url=${jdbc.url}
jdbc.user=${jdbc.user}
jdbc.password=${jdbc.password}
...

/src/main/resources/spring/applicationContext.xml

<beans ... xmlns:p="http://www.springframework.org/schema/p" ...>
    ...
    <bean
        id="dataSource"
        ...
        p:driverClassName="${jdbc.driver}"
        p:url="${jdbc.url}"
        p:username="${jdbc.user}"
        p:password="${jdbc.password}"
        ... />
    ...
</beans>

/src/test/java/com/company/project/service/MyItemServiceImplTest.java

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/spring/applicationContext.xml" })
public class MyItemServiceImplTest {

    @Resource
    private MyItemService myItemService;

    @Test
    public void testSave() {
        MyItem myItem = new MyItem();
        myItemService.save(myItem);
        ...
    }

}

Question

When running the tests, it throws an exception:

java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [spring/applicationContext.xml]: Could not resolve placeholder 'database.password'
...

I guess it’s because I need to run the tests while specifying the dev profile like I do when I launch the webapp (using -P dev). But I can’t make it work. Is it even possible?

PS

The filtered applicationContext.xml file (i.e. the one in /target/classes/spring/applicationContext.xml) is identical to the one in /src/*, but the filtered database.properties file (i.e. /target/classes/database.properties) looks like

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://${database.host}/${database.name}
jdbc.user=${database.user}
jdbc.password=${database.password}

It means that from the pom.xml file to the .properties one, the properties have been well filtered, but within the pom.xml itself, the properties that depend on the chosen profile won’t get filtered. Probably because I want to specify anywhere the profile I need when launching the tests. But as I said before, -P dev doesn’t seem work with JUnit…

  • 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-11T20:30:20+00:00Added an answer on June 11, 2026 at 8:30 pm

    Resource filtering is performed in the process-resources phase. So if you state mvn test -Pdev you will have passed that phase and all filtering has been done. It doesn’t matter to JUnit what profile you are running since you are not doing anything else differently in that dev profile.

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

Sidebar

Related Questions

*Please forgive the intricate title* Background /pom.xml ... <foo.bar>stackoverflow</foo.bar> ... /src/main/resources/config.properties ... foo.bar=${foo.bar} ...
Background A lot of work has gone into optimizing database design, especially in the
Background Detection of hash change in the URL and fixing the forward/back button are
I would like to have Maven download the JARs listed in a pom.xml file.
Background I have a form that PHP generates from my database. The page is
Background My project is urgent and requires that I iterate a large XML file
Background: What I need to accomplish is to remove any records in a collection
Background: We're building an application that allows our customers to supply data in a
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
Background - I am using paramiko to put files on a bunch of remote

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.