【问题标题】:proxyBeanMthods annotation error when running springboot application运行spring boot应用程序时proxyBeanMethods注解错误
【发布时间】:2019-03-22 05:18:42
【问题描述】:

我正在尝试运行我的第一个 springboot 应用程序,但遇到了一些问题。

在我的应用程序文件中,这是我的代码

package com.clog.ServiceMgmt;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EntityScan("models")
@ComponentScan({"com.clog.ServiceMgmt","controllers", "models", "repositories"})
@EnableJpaRepositories(basePackages={"repositories"})
public class ServiceMgmtApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceMgmtApplication.class, args);
    }

}

但是当我运行我的应用程序时,我收到以下错误。不知道为什么我应该得到这个错误以及如何解决它。

org.springframework.core.annotation.AnnotationConfigurationException: 注释中的属性“proxyBeanMethods” [org.springframework.boot.autoconfigure.SpringBootApplication] 是 在中声明为 @AliasFor 不存在的属性“proxyBeanMethods” 注释 [org.springframework.context.annotation.Configuration].; 嵌套异常是 java.lang.NoSuchMethodException: org.springframework.context.annotation.Configuration.proxyBeanMethods()

这是我的 pom.xml 文件

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.clog</groupId>
    <artifactId>ServiceMgmt</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>ServiceMgmt</name>
    <description>Service Mgmt</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-52</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>

有人知道如何解决这个问题吗?

谢谢

【问题讨论】:

  • 你有 @Configuration 注释类吗?
  • @MadhuBhat 不,我不知道。我应该有一个,如果是的话,我应该把它放在哪里?
  • 您能告诉我们您使用了哪些依赖项(+ 版本)吗?听起来您正在尝试将 2.2.0.M1 与旧版本的 Spring 一起使用。
  • spring-boot-2.2.0 快照
  • @g00glen00b 添加了我的 pom.xml 文件

标签: java spring spring-boot spring-boot-maven-plugin


【解决方案1】:

来自spring-projects-github

" proxyBeanMethods 是 5.2 中的新功能,我可以在堆栈的某些元素中看到 5.1.2.RELEASE。"

做一个依赖:树并仔细检查 spring match >= 5.2,我遇到了类似的问题,一个库从 springboot 带来了 5.1 覆盖 v5.2

【讨论】:

    【解决方案2】:

    几天前遇到了同样的问题。尝试将 spring-boot-starter-parent 版本更改为 2.1.3.RELEASE,这解决了我的问题。

    【讨论】:

    • 它将消除错误,但如果使用了 2.1.3 版本中不存在的某些内容,则可能会出现新错误
    【解决方案3】:

    我在一个 Spring Boot 项目中发生了这个错误,我在其中添加了一个使用 Spring(不是 Spring Boot)的自定义依赖项。我的自定义依赖项中的问题是它具有以下插件配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
            <execution>
                <phase>package</phase>
    
                <goals>
                    <goal>shade</goal>
                </goals>
    
                <configuration>
                    <transformers>
                        <transformer
    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.example.Main</mainClass>
                            <manifestEntries>
                                <Implementation-Title>${project.name}</Implementation-Title>
                                <Implementation-Version>${project.version}</Implementation-Version>
                                <Implementation-Vendor>Vendor Name, ${timestamp}</Implementation-Vendor>
                            </manifestEntries>
                        </transformer>
                    </transformers>
    
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    一旦我从自定义依赖项中删除了 shade 插件,错误就消失了。

    【讨论】:

      【解决方案4】:

      我删除了以下依赖项

      <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot</artifactId>
                  <version>2.2.1.RELEASE</version>
      </dependency>
      

      代码就像魔法一样出现了

      【讨论】:

        【解决方案5】:

        在你的主 springboot 应用程序类中使用它:@SpringBootApplication(proxyBeanMethods = false)

        这会起作用。

        【讨论】:

          猜你喜欢
          • 2015-04-18
          • 2017-02-18
          • 1970-01-01
          • 1970-01-01
          • 2018-06-04
          • 1970-01-01
          相关资源
          最近更新 更多