【问题标题】:Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE未能执行目标 org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE
【发布时间】:2017-07-30 14:10:36
【问题描述】:

我是 Spring Boot 新手,尝试解决这个问题一周。 我下载了plugin,但仍然出现同样的错误,如果需要,工具/选项我没有代理

编辑 我刚刚创建了一个用户可以注册或登录的基本项目。我有控制器、服务存储库、域类。但是当我想检查我的数据库是否已创建时,我得到了这个错误。如果我错过了,我检查了我的plugins有些,但一切似乎都是正确的。你能给我一些猜测可能是什么问题吗?

我的 pom.xml

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.1.0</version>
        <type>jar</type>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>1.13.6.RELEASE</version>
        <type>jar</type>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.11.6.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.6.RELEASE</version>
        <type>jar</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.6.RELEASE</version>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
        
    </plugins>
</build>

控制台

Description:

Field `userRepository` in `com.example.service.UserService` required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

【问题讨论】:

  • 你能在 pastebin 上发布堆栈跟踪或你得到的确切错误吗?更重要的是,在哪个修改之后开始出现错误?

标签: java spring maven


【解决方案1】:

只需将以下代码添加到您的pom.xml

100% 正常工作

<build>
<plugins>
 <plugin>
  <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
            <skip>true</skip>
         </configuration>
         <executions>
            <execution>
               <phase>none</phase>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>

【讨论】:

  • 这对我也有用,谢谢你的支持。
【解决方案2】:

我面临同样的问题,但情况不同。 我有一个 Maven 多模块项目。 我的核心模块继承自另一个使用spring-boot-maven-plugin:2.1.2.RELEASE 插件的模块。 当我尝试编译核心模块时,发生了同样的错误:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.2.RELEASE:repackage (repackage) on project it-core

我认为问题的出现是因为我的核心模块没有@SpringBootApplication 主类。

以下解决方案解决了我的问题。

<build>
   <plugins>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
            <skip>true</skip>
         </configuration>
         <executions>
            <execution>
               <phase>none</phase>
            </execution>
         </executions>
      </plugin>
      <plugin>
         <groupId>com.google.cloud.tools</groupId>
         <artifactId>jib-maven-plugin</artifactId>
         <configuration>
            <skip>true</skip>
         </configuration>
      </plugin>
   </plugins>
</build>

也许你不需要jib-maven-plugin

【讨论】:

    【解决方案3】:

    尝试删除以下内容

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.6.RELEASE</version>
        <type>jar</type>
    </dependency>
    

    <version>1.5.6.RELEASE</version>
            <configuration>
                <fork>true</fork>
            </configuration>
    

    【讨论】:

    • 重建项目
    • “但是当我想检查我的数据库是否已创建时出现此错误”是什么意思?
    • 我重建项目。我创建了扩展 CrudRepository 的 UserRepository 类并尝试连接到 MySql 。然后,当我想运行时,我收到此错误,您可以看到已编辑的问题控制台部分
    【解决方案4】:

    在控制器类中自动装配 UserService,在 UserService 类中自动装配 UserRepository。

    在 UserService 类中:

    @service
    public class UserService{
    
        @Autowired
        private UserRepository userRepository;
    
        ....
    }
    

    在控制器类中:

    @Controller
    class UserController{
    
          @Autowired
          private UserRepository userRepository;
    
          .....
    }
    

    【讨论】:

      【解决方案5】:

      您可能需要 spring-boot-maven-plugin 的目标配置,如下所示

       <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
      </executions>
      

      另外,你用来构建和运行的 maven 命令是什么?

      【讨论】:

      • 不幸的是,仍然出现同样的错误。我只是使用 netbeans 并运行项目
      • 请查看我的另一个答案,这可能对您有所帮助。
      • 非常感谢。我会检查它
      【解决方案6】:

      请定义 entityMangerFactory bean 并将其注入任何需要的地方,我认为您可能正在使用 JPA/Hibernate。试试这个

      【讨论】:

        猜你喜欢
        • 2020-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-27
        • 2021-11-23
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        相关资源
        最近更新 更多