简体   繁体   English

在 ExternalContext 中找不到作为资源错误(Amazon Elastic Beanstalk / Spring Boot / JSF + Primefaces)

[英]Not Found in ExternalContext as a Resource Error (Amazon Elastic Beanstalk / Spring Boot / JSF + Primefaces)

I created an app using Spring Boot, JSF + Primefaces.我使用 Spring Boot、JSF + Primefaces 创建了一个应用程序。 I deployed it to Amazon Elastic Beanstalk, and set the environment variables that project needed to use.我将它部署到 Amazon Elastic Beanstalk,并设置项目需要使用的环境变量。

When I tried to access my website, I got this error message:当我尝试访问我的网站时,收到以下错误消息:

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

Here is my Faces Config (as java class):这是我的 Faces 配置(作为 java 类):

    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
}

my faces config file under webapp/WEB-INF folder: 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>

and as you see, all my xhtml files are under webapp folder:如您所见,我所有的 xhtml 文件都在 webapp 文件夹下:

xhtml 文件

my application.properties file (using java params):我的 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}

and here are java parameters that I defined on Amazon (I will not post db params for security reasons):这是我在亚马逊上定义的 java 参数(出于安全原因,我不会发布数据库参数):

PORT=5000
CONTEXT_PATH=/
SPRING_DATASOURCE_DRIVERCLASSNAME=org.postgresql.Driver
...

and so on.等等。

Really I run out of solutions.真的我用完了解决方案。 With same packaged jar, I deployed to Heroku with same environment parameters, and it works flawlessly.使用相同封装的 jar,我以相同的环境参数部署到 Heroku,它可以完美运行。

Where I am doing wrong with Amazon Elastic Beanstalk? Amazon Elastic Beanstalk 我在哪里做错了?

Kind regards.亲切的问候。

I found the problem.我发现了问题。

Maven, does not add *.xhtml files inside "jar" package. Maven,不在“jar”package 中添加 *.xhtml 文件。 Here is the ss of decompiled version of jar packaging (with jd-gui)这里是反编译版jar打包的ss(带jd-gui)

jar反编译

..and here is the ss of war packaging: ..这是战争包装的ss:

战争包装

so if you are think that you did everything correct during development and managing after, check the packaging type.因此,如果您认为您在开发和管理过程中所做的一切都是正确的,请检查包装类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Spring启动应用程序登录Amazon Elastic Beanstalk - How to log on Amazon Elastic Beanstalk with a spring boot application Spring Boot无法在Elastic Beanstalk上运行 - Spring boot not working on Elastic Beanstalk Spring Boot和JSF / Primefaces / Richfaces - Spring Boot and JSF/Primefaces/Richfaces Spring Boot,Elastic Beanstalk错误,IDE没问题 - Spring Boot, Elastic Beanstalk error, no issue from the IDE 在AWS Elastic Beanstalk上部署Spring Boot应用程序 - 获得502错误 - Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error Spring-boot Amazon Elastic Beanstalk忽略&#39;SPRING_APPLICATION_JSON&#39; - Spring-boot Amazon Elastic Beanstalk ignores 'SPRING_APPLICATION_JSON' 使用 Amazon Linux 2 为使用 AWS Elastic Beanstalk 托管的 Java Spring Boot 应用程序添加 SSL 证书 - Add SSL certificate for Java Spring Boot App hosted using AWS Elastic Beanstalk using Amazon Linux 2 如何在部署到Elastic Beanstalk的Spring Boot项目中找到资源文件? - How do I locate resource files in a Spring Boot project deployed to Elastic Beanstalk? JAR中的Spring Boot + Elastic Beanstalk .ebextensions - Spring Boot + Elastic Beanstalk .ebextensions in JAR 带有弹簧启动应用程序的aws弹性beanstalk - aws elastic beanstalk with spring boot app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM