在哪里创建文件夹?

时间:2018-04-17 17:39:28

标签: java maven spring-boot database-connection

我正在创建一个Spring Boot应用程序并提供一些数据库支持。我追随的The tutorial要求我在applications.properties文件夹中创建一个resources文件。

这完全是花花公子,除了我根本没有任何resources文件夹。是因为我使用Eclipse,而教程遵循IntelliJ?我不这么认为。我的问题是 - 我在哪里创建这个resources文件夹?我会在其中插入带有数据库连接信息的applications.properties文件,因此{I}我可以访问此文件pom.xml。哦,我正在使用Maven进行构建(如果它有所作为)。

目前,我的目录结构如下:

My directory structure image.

2 个答案:

答案 0 :(得分:0)

Maven约定是将src/main/resources用于将与打包工件捆绑在一起的资源,并作为类路径资源提供。

要让Eclipse识别该文件夹并将这些文件视为类路径资源,需要将src/main/resources标记为源文件夹。

例如,这个Eclipse .classpath文件为Maven的常规文件夹结构设置了类路径:

<?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>

答案 1 :(得分:0)

假设您尝试从头开始构建一个Spring启动应用程序。 当srping提供非常方便且易于使用的弹簧靴锅炉板时,你真的不需要从头开始构建一个。 https://start.spring.io/

启动春季启动项目时,您需要了解的一些事项。 1.application.properties文件包含所有配置相关的date.Wondering如何从java类下面的代码中读取这个属性代码可以帮忙

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/

现在,spring boot会从application.properties文件中动态读取此值。

上面的链接还为您提供了构建项目gradle / maveen的方式。

以上锅炉板也有与之相关的测试框架工作。 它只是让工作变得轻松。

检查此链接 https://spring.io/guides/gs/spring-boot/

相关问题