【发布时间】:2017-08-29 09:00:27
【问题描述】:
我的问题是当我向配置文件添加依赖项时,代码中的所有内容都会“无法解析”。那个 pom 有什么问题?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa</groupId>
<artifactId>zzz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
... more dependencies...
</dependencies>
</profile>
<profile>
<id>test</id>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
还有一个问题 - 如果我有配置文件,某些依赖项是否可以在没有任何配置文件的情况下成为每个配置文件的一部分?感谢您的回答。
【问题讨论】:
-
如果你想使用它,你必须激活一个配置文件。但是,当您在代码中实际需要依赖项时,为什么还要在配置文件中添加依赖项呢?
-
我粘贴了错误的pom,现在已经编辑了。 :) 我想在测试中有其他数据库。
-
我在 application.properties 中有 spring.profiles.active=dev
标签: java spring maven spring-boot pom.xml