0

I am creating a Spring Boot application and providing some database support. The tutorial that I am following asks me to create a applications.properties file inside the resources folder.

This is all dandy, except that I do not have any resources folder at all. Is it because I am using Eclipse, while the tutorial follows IntelliJ? I don't think so. My question is - where do I create this resources folder? I would be inserting the applications.properties file with database connectivity info in it, so this file should be accessible to pom.xml I guess. Oh, and I am using Maven for building (in case it makes a difference).

Currently, my directory structure is as follows:

My directory structure image.

P.K.
  • 379
  • 1
  • 4
  • 16
  • I found something [here](https://stackoverflow.com/q/36907204/9656249), but I am not sure about the context of that question and whether I could follow the steps outlined. You see, our aims are similar but different. – P.K. Apr 17 '18 at 17:42

2 Answers2

0

The Maven convention is to use the src/main/resources for resources that will be bundled with the packaged artifact and available as classpath resources.

To get Eclipse to recognize that folder and treat those files as classpath resources, src/main/resources needs to be marked as a source folder.

As an example, this Eclipse .classpath file sets the classpath for Maven's conventional folder structure:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
    <attributes>
        <attribute name="optional" value="true"/>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
    <attributes>
        <attribute name="optional" value="true"/>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Brent Worden
  • 10,624
  • 7
  • 52
  • 57
0

Assuming that ur trying to build one spring boot application from scratch. You dont really need to do build one from scratch when srping provides spring boot boiler plate which is very handy and easy to use. https://start.spring.io/

Few things you need to know when ur starting a spring boot project. 1.application.properties file contains all the configuration related date.Wondering how to read this property from java class below code can help

Java class
@Configuration
public class JMSSQSConfig {
@Value("${queue.endpoint}")
private String endpoint;

application.properties file
#AWS Endpoint
queue.endpoint=https://sqs.us-west-2.amazonaws.com/

Now spring boot reads this value dynamically from application.properties file.

Above link also provides you the way u want to build ur project gradle/maveen.

Above boiler plate has testing frame work assosiated with it too.. It just makes work easy.

Check this link https://spring.io/guides/gs/spring-boot/

Rakshith R Pai
  • 202
  • 1
  • 5
  • 13