【问题标题】:Where to create the folder?在哪里创建文件夹?
【发布时间】:2018-09-27 18:53:45
【问题描述】:
我正在创建一个 Spring Boot 应用程序并提供一些数据库支持。我关注的The tutorial 要求我在resources 文件夹中创建一个applications.properties 文件。
这都是花花公子,除了我根本没有任何resources 文件夹。是因为我使用的是 Eclipse,而教程遵循 IntelliJ 吗?我不这么认为。我的问题是 - 我在哪里创建这个 resources 文件夹?我将插入带有数据库连接信息的applications.properties 文件,所以我猜pom.xml 应该可以访问这个文件。哦,我正在使用 Maven 进行构建(以防它有所作为)。
目前我的目录结构如下:
My directory structure image.
【问题讨论】:
-
我发现了一些东西 here,但我不确定该问题的上下文以及我是否可以按照概述的步骤进行操作。你看,我们的目标相似但不同。
标签:
java
maven
spring-boot
database-connection
【解决方案1】:
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>
【解决方案2】:
假设您尝试从头开始构建一个 Spring Boot 应用程序。
当 srping 提供了非常方便且易于使用的弹簧靴样板时,您真的不需要从头开始构建一个。
https://start.spring.io/
当您开始一个 Spring Boot 项目时,您需要知道的几件事。
1.application.properties 文件包含所有与配置相关的日期。想知道如何从下面的代码中的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/