Spring Boot Tiles - java.lang.NoClassDefFoundError: org/apache/commons/beanutils/MethodUtils

Spring Boot Tiles - java.lang.NoClassDefFoundError: org/apache/commons/beanutils/MethodUtils

我正在尝试配置 Spring Boot 1.4.3Apache tiles 3。使用下面的配置我得到:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/beanutils/MethodUtils

当我查看 MavenDependencis 时,包含 MethodUtils class 的 jar 文件 commons-beanutils-1.9.3 就在那里! 但是为什么嵌入式tomcat8.5.6看不到呢?

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>

    <groupId>io.boot.spring</groupId>
    <artifactId>Spring-Boot-RSSReader</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Spring-Boot-RSSReader</name>
    <description></description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.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.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>3.0.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId> 
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </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>

</project>

ConfigForTiles:

@Configuration
public class ConfigForTiles {

    @Bean
    public TilesConfigurer tilesConfigurer(){
        final TilesConfigurer configurer = new TilesConfigurer();
        configurer.setDefinitions(new String [] {"WEB-INF/tiles/tiles.xml"});
        configurer.setCheckRefresh(true);
        return configurer;
    }

    @Bean
    public TilesViewResolver tilesViewResolver(){
        final TilesViewResolver resolver = new TilesViewResolver();
        resolver.setViewClass(TilesView.class);
        return resolver;
    }
}

控制器:

@Controller
public class IndexController {

    @RequestMapping("/")
    public String index(){
        return "index";
    }
}

application.properties:

spring.mvc.view.prefix=/WEB-INF/jsp/

spring.mvc.view.suffix=.jsp

mvn dependency:tree

[INFO] Scanning for projects...
[INFO] +- org.apache.tiles:tiles-jsp:jar:3.0.5:compile
[INFO] |  |  |  +- commons-digester:commons-digester:jar:2.1:compile
[INFO] |  |  |  |  \- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] |  |  |  |     \- commons-collections:commons-collections:jar:3.2.2:compile

您的类路径中似乎有多个版本的 commons-beanutils

在您的 IDE 中,您可以搜索 commons-beanutils - 您应该能够找到 commons-beanutils 的多个版本。

可以帮助您调试的 Maven 命令:

mvn dependency:tree
mvn help:effective-pom

尝试从org.apache.tiles中排除commons-beanutils,如下:

    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>3.0.5</version>
        <exclusions>
          <exclusion>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
          </exclusion>
        </exclusions>
    </dependency>