在 ExternalContext 中找不到资源错误(Amazon Elastic Beanstalk / Spring Boot / JSF + Primefaces)
Not Found in ExternalContext as a Resource Error (Amazon Elastic Beanstalk / Spring Boot / JSF + Primefaces)
我使用 Spring Boot、JSF + Primefaces 创建了一个应用程序。我部署到Amazon Elastic Beanstalk,并设置项目需要使用的环境变量。
当我尝试访问我的网站时,收到此错误消息:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Mar 04 07:21:33 UTC 2021
There was an unexpected error (type=Not Found, status=404).
/login.xhtml Not Found in ExternalContext as a Resource
这是我的 Faces 配置(如 java class):
package com.jsf;
@SpringBootApplication
@Configuration
@ComponentScan("com.jsf")
public class HelloJsfApplication {
public static void main(String[] args) {
SpringApplication.run(HelloJsfApplication.class, args);
}
// JSF Configration Başlangıc
@Bean
public ServletRegistrationBean<FacesServlet> facesServletRegistraiton() {
ServletRegistrationBean<FacesServlet> registration = new ServletRegistrationBean<FacesServlet>(
new FacesServlet(), new String[] { "*.xhtml" });
registration.setName("Faces Servlet");
registration.setLoadOnStartup(1);
registration.addUrlMappings("*.xhtml");
return registration;
}
@Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
servletContext.setInitParameter("primefaces.THEME", "bootstrap");
// Primefaces client browser tarafında kontrol edilebilme örneğin textbox 10
// karakter olmalı vs..
servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", Boolean.TRUE.toString());
// Xhtml sayfalarında commentlerin parse edilmemesi.
servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
// primefaces icon set için
servletContext.setInitParameter("primefaces.FONT_AWESOME", Boolean.TRUE.toString());
};
}
@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
}
// JSF Configration Sonu
}
webapp/WEB-INF 文件夹下的我的面部配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
如您所见,我所有的 xhtml 文件都在 webapp 文件夹下:
我的 application.properties 文件(使用 java 参数):
server.servlet.context-path = ${CONTEXT_PATH}
server.port = ${PORT}
spring.datasource.url = ${SPRING_DATASOURCE_URL}
spring.datasource.username = ${SPRING_DATASOURCE_USERNAME}
spring.datasource.password = ${SPRING_DATASOURCE_PASSWORD}
spring.jpa.properties.hibernate.dialect = ${SPRING_JPA_DATABASE_PLATFORM}
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = ${SPRING_JPA_HIBERNATE_DDL_AUTO}
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=${SPRING_JPA_HIBERNATE_LOB_CREATION}
spring.datasource.driver-class-name=${SPRING_DATASOURCE_DRIVERCLASSNAME}
这是我在 Amazon 上定义的 java 参数(出于安全原因,我不会 post db 参数):
PORT=5000
CONTEXT_PATH=/
SPRING_DATASOURCE_DRIVERCLASSNAME=org.postgresql.Driver
...
等等。
真的我运行无解。使用相同的打包jar,我使用相同的环境参数部署到Heroku,并且它完美运行。
Amazon Elastic Beanstalk 哪里做错了?
亲切的问候。
我发现了问题。
Maven,不在“jar”包内添加 *.xhtml 文件。
这里是jar打包反编译版的ss(带jd-gui)
..这是war包装的ss:
因此,如果您认为自己在开发和管理过程中所做的一切都是正确的,请检查包装类型。
我使用 Spring Boot、JSF + Primefaces 创建了一个应用程序。我部署到Amazon Elastic Beanstalk,并设置项目需要使用的环境变量。
当我尝试访问我的网站时,收到此错误消息:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Mar 04 07:21:33 UTC 2021
There was an unexpected error (type=Not Found, status=404).
/login.xhtml Not Found in ExternalContext as a Resource
这是我的 Faces 配置(如 java class):
package com.jsf;
@SpringBootApplication
@Configuration
@ComponentScan("com.jsf")
public class HelloJsfApplication {
public static void main(String[] args) {
SpringApplication.run(HelloJsfApplication.class, args);
}
// JSF Configration Başlangıc
@Bean
public ServletRegistrationBean<FacesServlet> facesServletRegistraiton() {
ServletRegistrationBean<FacesServlet> registration = new ServletRegistrationBean<FacesServlet>(
new FacesServlet(), new String[] { "*.xhtml" });
registration.setName("Faces Servlet");
registration.setLoadOnStartup(1);
registration.addUrlMappings("*.xhtml");
return registration;
}
@Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
servletContext.setInitParameter("primefaces.THEME", "bootstrap");
// Primefaces client browser tarafında kontrol edilebilme örneğin textbox 10
// karakter olmalı vs..
servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", Boolean.TRUE.toString());
// Xhtml sayfalarında commentlerin parse edilmemesi.
servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", Boolean.TRUE.toString());
// primefaces icon set için
servletContext.setInitParameter("primefaces.FONT_AWESOME", Boolean.TRUE.toString());
};
}
@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
}
// JSF Configration Sonu
}
webapp/WEB-INF 文件夹下的我的面部配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
如您所见,我所有的 xhtml 文件都在 webapp 文件夹下:
我的 application.properties 文件(使用 java 参数):
server.servlet.context-path = ${CONTEXT_PATH}
server.port = ${PORT}
spring.datasource.url = ${SPRING_DATASOURCE_URL}
spring.datasource.username = ${SPRING_DATASOURCE_USERNAME}
spring.datasource.password = ${SPRING_DATASOURCE_PASSWORD}
spring.jpa.properties.hibernate.dialect = ${SPRING_JPA_DATABASE_PLATFORM}
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = ${SPRING_JPA_HIBERNATE_DDL_AUTO}
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=${SPRING_JPA_HIBERNATE_LOB_CREATION}
spring.datasource.driver-class-name=${SPRING_DATASOURCE_DRIVERCLASSNAME}
这是我在 Amazon 上定义的 java 参数(出于安全原因,我不会 post db 参数):
PORT=5000
CONTEXT_PATH=/
SPRING_DATASOURCE_DRIVERCLASSNAME=org.postgresql.Driver
...
等等。
真的我运行无解。使用相同的打包jar,我使用相同的环境参数部署到Heroku,并且它完美运行。
Amazon Elastic Beanstalk 哪里做错了?
亲切的问候。
我发现了问题。
Maven,不在“jar”包内添加 *.xhtml 文件。 这里是jar打包反编译版的ss(带jd-gui)
..这是war包装的ss:
因此,如果您认为自己在开发和管理过程中所做的一切都是正确的,请检查包装类型。