运行springboot应用程序时,proxyBeanMthods注释错误

时间:2019-03-22 05:18:43

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

我正在尝试运行我的第一个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>

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

谢谢

5 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

来自spring-projects-github

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

执行一个依赖项:树并再次检查spring匹配是否大于5.2,我遇到了类似的问题,一个库从springboot中引入了5.1覆盖v5.2。

答案 3 :(得分:0)

我删除了以下依赖项

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

代码就像魔术一样

答案 4 :(得分:0)

在您的主要 spring-boot 应用程序类中使用它:

:@SpringBootApplication(proxyBeanMethods = false)