sitemesh / sitemesh3

SiteMesh 3: Official repository
https://sitemesh.github.io/sitemesh-website/
Apache License 2.0
480 stars 168 forks source link

can sitemesh3 be used by spring boot 3.x ? #129

Closed Frank0321 closed 1 year ago

Frank0321 commented 1 year ago

spring boot 3.x must be to use java 17 In java 17, almost javax is replace by jakarta like javax.servlet.Filter is replace to javax.servlet.Filter

when I extend ConfigurableSiteMeshFilter to setting decorator

public class WebSiteMeshFilter extends ConfigurableSiteMeshFilter{

     @Override
        protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
            builder.addDecoratorPath("/*", "/WEB-INF/views/decorator.jsp");
     }
}

and implements WebMvcConfigurer

@Configuration
public class WebSiteMeshConfig implements WebMvcConfigurer{

   @Bean
    public FilterRegistrationBean siteMeshFilter() {
        FilterRegistrationBean filter = new FilterRegistrationBean();
        WebSiteMeshFilter siteMeshFilter = new WebSiteMeshFilter();
        filter.setFilter(siteMeshFilter);
        return filter;
    }

}

it show me error The method setFilter(Filter) in the type FilterRegistrationBean is not applicable for the arguments (WebSiteMeshFilter)

that is because setFilter is use jakarta.servlet.Filter but ConfigurableSiteMeshFilter is implements Filter (javax.servlet.Filter)

I try use cast to let javax.servlet.Filter to be jakarta.servlet.Filter but when run this project, it show me ConfigurableSiteMeshFilter cannot be cast to class jakarta.servlet.Filter how can I do to fix this question ?

MatthewRichardsonICPSR commented 1 year ago

To provide some context:

"Jakarta EE 9 a new top-level jakarta package, replacing EE 8's javax top-level package. For example, the Servlet specification in Jakarta EE 8 uses a javax.servlet package but this has changed to jakarta.servlet in EE 9."

"Generally speaking, it's not possible to mix Java EE and Jakarta EE APIs in the same project. You need to ensure that your own code, as well as all third-party libraries are using jakarta.* package imports."

https://spring.io/blog/2022/05/24/preparing-for-spring-boot-3-0

This implies the need for a version of SiteMesh that is updated to use jakarta instead of javax (I think).

PaulJamesMoran commented 1 year ago

I took a copy to experiment with and was able to change the javax. to jakarta.. The new jar seems to work well with SpringBoot3.

I was not able to get the tests working. I don't fully understand Jetty etc. But happy to share what I have done if anyone is interested.

codeconsole commented 1 year ago

Here is a full working example with Spring Boot 3.1.1:

https://github.com/sitemesh/sitemesh3/tree/jakarta/sitemesh-examples-springboot