You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot中Pretty Faces无法正常工作问题求助

Pretty Faces配置文件未读取导致"No mapping for GET"问题排查与解决

问题场景

  • 配置pretty-config.xml实现URL映射,但文件未被Spring Boot应用识别
  • 访问目标URL时控制台输出No mapping for GET错误
  • 尝试在@SpringBootApplication类中手动添加过滤器后触发500服务器错误

排查与解决方案

1. 校验依赖配置

确保引入适配Spring Boot版本的Pretty Faces Starter依赖:
Maven

<dependency>
    <groupId>com.ocpsoft</groupId>
    <artifactId>prettyfaces-spring-boot-starter</artifactId>
    <version>4.0.1.Final</version>
</dependency>

Gradle

implementation 'com.ocpsoft:prettyfaces-spring-boot-starter:4.0.1.Final'

Spring Boot 2.x对应Pretty Faces 4.x版本,若使用Spring Boot 3.x需确认是否有兼容版本

2. 确认配置文件位置

pretty-config.xml必须放在src/main/resources/META-INF/目录下,这是框架默认的扫描路径,其他位置无法被自动识别。

3. 检查配置文件语法正确性

确保XML结构符合规范,示例正确配置:

<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
                                   http://ocpsoft.org/xml/ns/rewrite/rewrite-config-prettyfaces.xsd">

    <url-mapping id="demo">
        <pattern value="/demo" />
        <view-id value="/demo.xhtml" />
    </url-mapping>

</pretty-config>

4. 删除手动添加的过滤器

Pretty Faces Spring Boot Starter已自动完成过滤器注册,手动添加会导致冲突引发500错误,移除@SpringBootApplication类中类似如下的代码:

// 移除该类过滤器注册代码
@Bean
public FilterRegistrationBean<PrettyFilter> prettyFilterRegistration() {
    FilterRegistrationBean<PrettyFilter> registration = new FilterRegistrationBean<>();
    registration.setFilter(new PrettyFilter());
    registration.addUrlPatterns("/*");
    return registration;
}

5. 开启调试日志定位问题

在application.properties中添加日志配置,查看框架初始化细节:

logging.level.com.ocpsoft.prettyfaces=DEBUG
logging.level.org.ocpsoft.rewrite=DEBUG

启动应用后,检查日志中是否存在Loaded configuration file: META-INF/pretty-config.xml,确认配置文件是否被加载。

6. 确保自动配置未被禁用

检查application.properties中是否存在禁用Pretty Faces自动配置的配置项,若有则删除:

# 删除该行配置
spring.autoconfigure.exclude=com.ocpsoft.prettyfaces.spring.boot.PrettyFacesAutoConfiguration

内容的提问来源于stack exchange,提问作者bordinhon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 14:35:21