簡體   English   中英

SEO 用戶友好 url 使用漂亮的面孔和 spring 引導

[英]SEO user friendly url using Pretty faces and spring boot

我已經按照這個來配置 spring 啟動工作與 JSF 和配置是好的但是我需要擺脫我所有 Z7014702D6D714B9AF55887C1FFC0B972 面孔中的.xhtml 后綴。 到目前為止,我已經設法在我的 spring 啟動中配置 PrettyFaces RewriteFilter 並在我的托管 bean 中添加了 URLMapping,但它似乎沒有工作我得到“ Whitelabel Error Page ”。 這是我的登錄托管 bean

@Scope(value = "session")
@Component(value = "loginMgr")
@URLMapping(id = "login",
        pattern = "/login",
        viewId = "/my_context/login.xhtml")
public class LoginManager {

}

和我漂亮的面孔配置bean

@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 boot application.properties

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 及以下是漂亮的面孔 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。

注意:它可能會拋出一個異常,即無法從未在#getServletRegistrationsweb-fragment.xml中配置的偵聽器調用web.xml In this case you need to add org.apache.myfaces.webapp.StartupServletContextListener to your web.xml or web-fragment.xml ..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM