我已经按照 这个 配置spring boot工作与JSF,配置是确定的,但我需要摆脱.xhtml后缀在我所有的jsf使用pretty faces。到目前为止,我已经在我的spring boot中配置了PrettyFaces RewriteFilter,并在我的managed bean中添加了URLMapping,但似乎并不奏效,我得到了''。白标错误页面'. 这是我的登录管理豆
@Scope(value = "session")
@Component(value = "loginMgr")
@URLMapping(id = "login",
pattern = "/login",
viewId = "/my_context/login.xhtml")
public class LoginManager {
}
和我的漂亮脸蛋配置豆
@Bean
public FilterRegistrationBean prettyFilter() {
System.out.println("pretty filter called");
RewriteFilter filter=new RewriteFilter();
FilterRegistrationBean prettyFilter = new FilterRegistrationBean(filter);
prettyFilter.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.REQUEST,
DispatcherType.ASYNC, DispatcherType.ERROR);
prettyFilter.addUrlPatterns("/*");
return prettyFilter;
}
这是我的sping引导应用程序.属性。
spring.datasource.url= jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=password
#spring.jpa.show-sql=true
spring.datasource.driver-class-name=org.postgresql.Driver
#spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
server.context-path=/my_context
spring.security.enabled=false
management.security.enabled=false
security.basic.enabled=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrateg
我使用的是jsf 2.2和primefaces 5.3,下面是pretty faces的maven依赖关系。
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>3.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-integration-faces</artifactId>
<version>3.4.1.Final</version>
</dependency>
如果你想去掉.xhtml后缀而使用MyFaces 2.3,你可以简单地设置:org.apache.myfaces.AUTOMATIC_EXTENSIONLESS_MAPPING
为 true
.
所以你不需要PrettyFaces或Rewrite。
注意:它可能会抛出一个异常 #getServletRegistrations
不能从一个没有配置在 web.xml
或 web-fragment.xml
.在这种情况下,你需要添加 org.apache.myfaces.webapp.StartupServletContextListener
对你的 web.xml
或 web-fragment.xml
..