Spring Boot Application not reading application.properties file when using Maven test Spring Boot Application not reading application.properties file when using Maven test spring spring

Spring Boot Application not reading application.properties file when using Maven test


Try to define the <resources> tag in the build section in your pom, setting path for resource directory where is application.properties:

<build>        <resources>            <resource>                <directory>resources</directory>                <targetPath>${project.build.outputDirectory}</targetPath>                <includes>                    <include>application.properties</include>                </includes>            </resource>        </resources></build>


You can configure your main datasource as the following, I'm using mysql here. But you can use your own datasource. you can configure the following in your application.properties inside src/main/resources

spring.datasource.url = jdbc:mysql://localhost:3306/dsmspring.datasource.username = rootspring.datasource.password = admin123spring.datasource.testWhileIdle = truespring.datasource.validationQuery = SELECT 1spring.jpa.show-sql = truespring.jpa.hibernate.ddl-auto = updatespring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategyspring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

to run test inside your application you can either use the same datasource or create application-test.properties inside src/test/resources and its possible to configure test data source over there.


Just add the following statement;

@TestPropertySource("classpath:application.properties")

To your test class. I am assuming you have your application.properties file under src/test/resources

Here is my working example;

@RunWith(SpringJUnit4ClassRunner.class)@TestPropertySource("classpath:application.properties")public class TestTwitterFeedRoute extends CamelTestSupport {//...}