【问题标题】:how to Integrate spring boot in project如何在项目中集成spring boot
【发布时间】:2018-02-28 11:52:19
【问题描述】:

也许我的问题有点基础,但我很少使用弹簧靴。在这里我创建了一个这样的项目并有一些问题:

  1. 为什么我需要使用 add spring-boot-starter-parent 作为父级?其中<relativepath />的用法是什么?
  2. 我已经在pom.xml中添加了spring-boot-starter-web,一切正常,但是我的.java文件出现FilterRegistrationBean not found,是编译错误!为什么?这里我可以在project structure中看到这样的jar文件依赖(这里我用的是Idea 2016)

这是我的项目pom.xml文件sn-p,希望有人能帮帮我,谢谢:

<groupId>org.demo</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
    <relativePath />
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.5.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>1.5.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.0.14.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>jackson-mapper-asl</artifactId>
                <groupId>org.codehaus.jackson</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

更新:

经过将近半小时的发现,我发现这是一个Idea bug。可能之前在classpath下找不到这样的类,但是更改正确的版本依赖并重新组织导入(只需删除此类错误导入并自动导入新的)后,应用程序可以正常启动。这么奇怪 !也许我应该向 JetBrain 报告。 最后,无论如何,谢谢大家给我提示,我会为你投赞成票~.~.

这是我最后的pom.xml,如果你想检查你已经在Idea中下载的依赖项,你可以看到*.iml文件(有很多type='library'条目):

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
    <relativePath />
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.0.14.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>jackson-mapper-asl</artifactId>
                <groupId>org.codehaus.jackson</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

【问题讨论】:

  • 添加一些东西作为父意味着它将继承父pom的依赖关系,你可以很好地将它添加为&lt;dependencyManagement&gt; &lt;dependencies&gt; &lt;/dependencies&gt; &lt;/dependencyManagement&gt;
  • 请给我们一些代码
  • 您正在创建一个新项目吗?或者尝试在现有项目中使用引导?
  • @bestwishes 所以我不能直接将它添加为父级?但这样我仍然可以在类路径中看到一些 jar 依赖项
  • @Can'tTell 一个新项目

标签: java maven spring-boot intellij-idea


【解决方案1】:

可能无法解决实际问题,但您不需要在 pom.xml 中的所有启动器上都包含一个版本。

您已经为 spring-boot-starter-parent 指定了一个版本,因此它将负责为您的依赖项中的所有其他启动器使用正确的版本。

【讨论】:

  • 所以如果我添加一个 spring-boot-starter-parent 作为父级,那么我不需要指定其他依赖启动器版本,因为已经在父级中指定了它?
  • 正确 - 让 Spring Boot 负责启动器依赖项的版本管理。您可以覆盖版本号,但不建议这样做:spring.io/blog/2016/04/13/…
猜你喜欢
  • 1970-01-01
  • 2022-01-26
  • 2015-07-09
  • 1970-01-01
  • 2020-08-04
  • 2016-12-17
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
相关资源
最近更新 更多