Why is the JSP page not rendered while deploying a SpringBoot App in Pivotal Web Services while it works fine with Thymeleaf and other views - spring

The application is deployed in pivotal web services and when I hit the application with the link https://webstore.cfapps.io/, the login.jsp page is not rendered.
The same application runs successfully in the local server. I tried for searching the same issue but none of them solve the problem. I used both STS deployment and also tried cf command line for deploying separately but couldn't get the result.
I am giving you the details.
The error shown.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Jan 14 04:21:40 UTC 2017
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/login.jsp
My pom file is
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
ecommerce.com
webstore
0.0.1-SNAPSHOT
jar
ecommerce-webstore
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.4.2.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot</groupId> spring-boot-starter-security</artifactId>
</dependency> -->
org.springframework.boot
spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
org.springframework.boot
spring-boot-maven-plugin
3.MY application.properties file is
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
spring.datasource.url= jdbc:mysql://localhost:3306/ecommercestore
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
3.The manifest.yml generated after deployment is
applications:
name: webstore
memory: 1024M
host: webstore
domain: cfapps.io
buildpack: standard buildpack provided in git hub. I am not writing link
services:
cleardb
The result after giving the following command from cmd is
cf push webstore -p target/webstore-0.0.1-SNAPSHOT.jar --no-start
......................................................................
C:\Users\santosh dahal\Desktop\excellerant\ecommerce-webstore>cf push webstore -p target/webstore-0.0.1-SNAPSHOT.jar --no-start
Creating app webstore in org santosh-org / space Myspace as santoshdahal2072#gmail.com...
OK
Using route webstore.cfapps.io
Binding webstore.cfapps.io to webstore...
OK
Uploading webstore...
Uploading app files from: C:\Users\SANTOS~1\AppData\Local\Temp\unzipped-app904639435
Uploading 478.9K, 140 files
Done uploading
OK
6. I went to myapp in pivotal and started the application after binding the database cleardb to the same instant and application, the application runs successfully with the Running Status
7. the folder arrangement is as follows:
I have kept jsp pages in
src/main/webapp/WEB-INF/jsp/login.jsp
While the application.properties is in src/main/resources.
I will provide more details if needed. the github link for the code is
here

you are packaging it as a jar not as a war . In that case put your jsp files into static folder under resources or follow the below the link to understand better on the packaging aspect. But I feel it is better to package it as a war
Package a spring boot application including JSPs and static resources.
Also please check the jar generated before pushing the app to PWS whether jsp is avaibale at the requested path.

Related

Deploy spring boot application in external Jetty server

I am trying to deploy the spring boot application in external jetty server. I build the application with maven build tool by excluding the tomcat in pom.xml file and the able to generate the war file.
pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>
When I deploy the generated war file into webapp folder the war file is not getting extracted by jetty server.
I even tried to extract manually and try to access the application by postman, but no luck.
But same application when I try to run jar file instead of war file, it works fine.
Can I know how to deploy the spring boot application in jetty server.
Note: In code level I do not made any code change apart from the pom.xml to make application run in external jetty server.

change default web server on spring-boot 2.4.4

I'm working with Spring Boot 2.4.4 and I would change the default web server Tomcat to undertow orJHetty but I find it very difficult using both Gradle or Maven.
An old documentation exposes how do it but I'm sure all is changed because now tomcat, undertow and jetty configuration is embedded in the core library:
https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/howto-embedded-web-servers.html
How do it in the 2.4.4 version?
There are no changes between the versions. This is well described right at the Spring Boot 2.4.4 Reference guide, right in 3.1. Use Another Web Server section. Basically, the change consists of two steps:
Exclude embedded Tomcat server dependency from the spring-boot-starter-web artifact:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
Include your embedded server as a separate dependency instead:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Just don't forget to notice the following quote from the reference guide in the very same section which might or might not be relevant to you:
The version of the Servlet API has been overridden as, unlike Tomcat 9 and Undertow 2.0, Jetty 9.4 does not support Servlet 4.0.
follow three steps to change the default web server, change configuration in pom.xml.
1.exclude the default web server.
2.Include the necessary web server.
3.Maven update.
For example,
Instead of this
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
Add this one
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
for the necessary server add the appropriate web server dependency.

Spring Boot logging with Log4j2

Written simple POC to prove and test Spring Boot and log4j2 compatibility. Once successful I will move it to real application.
Please refer my POC source code:
https://github.com/Dennyss/SpringBootLog4j2POC
I know/read about Spring version and log4j2 compatibility from:
How to set up Spring Boot and log4j2 properly?
Found and tried recommendations described here:
Spring-Boot logging with log4j2?
But still not working. The problem is that both application logs and Spring logs are printing to console only.
Please refer maven dependencies below (from POC):
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
If I don't exclude Spring's logback and don't add boot-starter-log4j2 then application logs are printing to application file but Spring logs are not printing at all. I feel the problem somewhere with dependencies. Appreciate any help.
According to the Spring Boot Logging documentation, the location of the logging configuration file can be specified using the logging.config property. I noticed that your start.sh script is passing -Dlog4j.configurationFile. Normally, this would be sufficient for direct Log4J 2 integration, but Spring Boot uses logging.config.
After switching to this, it writes to the log files:
java -Dlogging.config=/share/LogPOC/log4j2.xml -cp poc.jar:libs/* com.poc.logger.Application

JSP with JSTL not working on tomcat 8 in a Spring Boot Application

I have include these dependency in pom.xml.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Still i am getting javax.servlet.ServletException: java.lang.NoSuchMethodError: org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
I also included one more dependency in pom.xml.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Then the error changed to An exception occurred processing JSP page /WEB-INF/views/index.jsp at line 7 4: <%# page session="false" %> [[[[ JSTL CODE USING EXPRESSION LANGUAGE]]]
Everything is working fine in eclipse ide but not working on deploying on separate tomcat server.
You are getting below error because of the presence of tomcat-embed-el-8.0.32.jar in your Tomcat 8.0\webapps\AppName\WEB-INF\lib folder.
javax.servlet.ServletException: java.lang.NoSuchMethodError:
org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
This error is due to the conflict between the ELSupport.class provided by Tomcat and tomcat-embed-el-8.0.32.jar present in the applications lib directory, hence you get that error in Tomcat. And it works fine in Eclipse since it uses embedded server.
To fix this issue add below code in your pom.xml:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<scope>provided</scope>
</dependency>
When you add tomcat-embed-el dependency as scope=required then the tomcat-embed-el-8.0.32.jar will not be added into your \AppName\WEB-INF\lib folder.
For information check this Issue on Spring-Boot's Github repository.
Also you can use these sample apps:
Spring-Boot-Jsp-Demo configured with InternalResourceViewResolver bean.
spring-boot-sample-tomcat-jsp configured with application.properties just like in the spring-boot sample apps.

Maven generated ear file fails during deploying weblogic server

I use JDeveloper 12.1.2.0.0 with Oracle Weblogic Server. Java version is 1.7.0_15.
I have got a project based on Oracle ADF. I have to mavenize it.
First of all I click on deploy the application ear file has created and working well on the server.
In my application there is Model and ViewController projects.
To mavenize I've just created Maven POM for project to every projects and finally an Application POM to the application.
The end product should be ear file to deploy on remote server with administration console so I modified a little the application POM (removed the Model and ViewController modules and then I could change the packaging from pom to ear).
When I maven install all of them build has ended successfully.
During deploying ear file to the Weblogic Server I got
java.lang.ClassNotFoundException: org.apache.myfaces.trinidad.webapp.ResourceServlet
I added these lines to my ViewController pom.xml:
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.2.4</version>
</dependency>
Deploying again I got this error and don't have idea what to do:
Caused by: java.lang.NullPointerException
at weblogic.servlet.internal.WebAnnotationProcessor.processMultipartConfigAnnotation(WebAnnotationProcessor.java:286)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotationForClasses(AnnotationProcessingManager.java:169)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:114)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotationsOutsideWebFragment(AnnotationProcessingManager.java:141)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:102)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:79)
at weblogic.servlet.tools.WARModule.processAnnotations(WARModule.java:491)
at weblogic.servlet.tools.WARModule.processAnnotations(WARModule.java:578)
at weblogic.servlet.tools.WARModule.merge(WARModule.java:526)
at weblogic.application.compiler.ToolsModuleWrapper.merge(ToolsModuleWrapper.java:96)
at weblogic.application.utils.CustomModuleManager.merge(CustomModuleManager.java:78)
at weblogic.application.compiler.flow.MergeModuleFlow.compile(MergeModuleFlow.java:38)
at weblogic.application.compiler.FlowDriver$FlowStateChange.next(FlowDriver.java:70)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.compiler.FlowDriver.nextState(FlowDriver.java:37)
at weblogic.application.compiler.BaseMerger.merge(BaseMerger.java:20)
at weblogic.application.compiler.flow.AppMergerFlow.mergeInput(AppMergerFlow.java:75)
at weblogic.application.compiler.flow.AppMergerFlow.compile(AppMergerFlow.java:40)
at weblogic.application.compiler.FlowDriver$FlowStateChange.next(FlowDriver.java:70)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.compiler.FlowDriver.nextState(FlowDriver.java:37)
... 75 more
By the way I compared the deployed (right click on application -> deploy) and created by maven ear file. I found some differences:
Maven generated ear file contains Model-1.0-SNAPSHOT.jar in WEB-INF\lib\ altough deployed has got the Modell project's class files in WEB-INF\classes.
Anyway when I update the dependecies section in pom.xml after first maven install nothing happens (it adds the new dependecies, but if I remove some of them after maven install it contains them. ?maven clean package?).
Any help would be highly appreciated.
To get around this issue, I used the following in my web layer pom.xml:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.2</version>
</dependency>
and the following weblogic-application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd
http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
<prefer-application-packages>
<package-name>javax.el.*</package-name>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.el.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/services/com.sun.faces.*</resource-name>
</prefer-application-resources>
</weblogic-application>
There are more details in this post: Deploying a JSF 2.2 to WebLogic 12.1.3

Resources