我有一个 MyFaces 应用程序正在运行Spring Boot 2.0.3
, all Servlets
and Context Listeners
已正确注册和配置,并且显然可以正常工作。就连我的index.jsf
页面正在渲染。标签已正确处理.xhtml
file.
问题是所有的EL expressions
的index.jsf 页面没有被处理/评估。没有抛出错误,但是我放置的位置#{myBean.property}
总是被渲染为空String
。调试它我发现我的托管 bean 的服务器代码没有被调用。
我尝试更改许多版本的 el-api 和 el-impl 库,但没有人工作。我使用的最终版本是el-api 2.2
规格,如下页https://myfaces.apache.org/core23/myfaces-impl/dependency.html
由于没有抛出任何错误,我无法弄清楚问题出在哪里。有人有这个错误吗?是否可以在打包为 jar 文件的 Spring Boot 应用程序下运行 MyFaces 2.3?
以下是我在 Gradle 构建文件上使用的依赖项:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile("org.jetbrains.kotlin:kotlin-reflect")
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'io.github.microutils:kotlin-logging:1.5.4'
compile group: 'org.apache.myfaces.core', name: 'myfaces-impl', version: '2.3.1'
compile group: 'org.apache.myfaces.core', name: 'myfaces-api', version: '2.3.1'
compile group: 'javax.enterprise', name: 'cdi-api', version: '2.0' //CDI vem embutido no JavaEE 6, mas não no Tomcat 9
compile group: 'org.glassfish.web', name: 'el-impl', version: '2.2'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot
compile 'org.springframework.boot:spring-boot-starter-web:2.0.3.RELEASE'
compile 'org.apache.tomcat.embed:tomcat-embed-jasper:8.5.32'
compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.6'
compile group: 'org.ocpsoft.rewrite', name: 'rewrite-servlet', version: '3.4.2.Final'
}
以下是加载 Faces servlet 的 Spring 配置:
@Component
open class ConfigureJSF : ServletContextInitializer {
private val logger = KotlinLogging.logger {}
@Throws(ServletException::class)
override fun onStartup(servletContext: ServletContext) {
//necessary to myfaces be enabled and work in spring boot, once servlets are loaded dynamically.
servletContext.setInitParameter("org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE", "true")
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", "true");
servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true");
servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml")
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "1")
servletContext.setInitParameter("org.apache.myfaces.EXPRESSION_FACTORY", "com.sun.el.ExpressionFactoryImpl")
servletContext.setInitParameter("org.apache.myfaces.CACHE_EL_EXPRESSIONS", "alwaysRecompile")
}
// Register ServletContextListener, necessary for Myfaces.
@Bean
open fun listenerRegistrationBean1(): ServletListenerRegistrationBean<ServletContextListener> {
val bean = ServletListenerRegistrationBean<ServletContextListener>()
bean.setListener(org.apache.myfaces.webapp.StartupServletContextListener())
return bean
}
@Bean
fun requestContextListener(): RequestContextListener {
return RequestContextListener()
}
//The faces servlet
@Bean
open fun facesServlet(): ServletRegistrationBean<MyFacesServlet> {
logger.info { "Criando Faces Servlet..." }
val servlet = org.apache.myfaces.webapp.MyFacesServlet() ;
val servletRegistrationBean = ServletRegistrationBean(servlet, "*.jsf", "*.xhtml")
servletRegistrationBean.setLoadOnStartup(1)
// servletRegistrationBean.order = 1;
return servletRegistrationBean;
}
Edit:
我复制了另一个有效项目的依赖配置,出现了相同的结果。所以,问题不在于我粘贴在这里的代码,是的,在于我的环境,我将开始更详细地调查序列。我的有问题的环境包含JDK 8, 9 and 10
and Tomcat 9
。我的项目目标是JDK 8
。也许这里存在一些不兼容,这就是一些编译注释找不到的原因,我相信我很快就会发现这个问题。