Spring Boot application deployed to Glassfish gives strange results

As mentioned here , I have a hell of a lot of time for my small Spring-Boot project to "deploy" correctly to Glassfish. It works fine using the built-in Tomcat, but as soon as I try to move it to my organization environment (Glassfish 3.1.2), I get strange behavior.

Thinking it was my code, I went back to the time-tested "Hello World" -approach and created a super basic application after this tutorial on the Spring blog .

I made some very minor deviations, but nothing that could affect the application happened.

The only significant deviation I made was that I found that I could not exclude "spring-boot-starter-tomcat" from "spring-boot-starter-web" - when I tried to do this, I got 2 errors in STS markers "Markers" "-tab:

The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletContext. Fix the build path then try building this project The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files Application.java 

If I cleaned up the STS project and then ran Maven Clean, Update, Install the Install, the following error was installed:

 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure [ERROR] /Users/brandon_utah/Utah Development/sts_workspaces/NidTools Rebooted/test/src/main/java/test/Application.java:[13,8] cannot access javax.servlet.ServletException [ERROR] class file for javax.servlet.ServletException not found 

So instead, I included this dependency (which I found mentioned in several other SpringBoot resources):

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> 

In this case, it was deployed on the built-in Tomcat, and it was deployed on my Glassfish (local installation), but with a whole bunch (about half a dozen) of errors like this:

 2014-04-03T16:23:48.156-0600|SEVERE: Class [ Lorg/springframework/jdbc/datasource/embedded/EmbeddedDatabase; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration ] 

Most of them are serious, but I also get a few with a warning:

 2014-04-04T06:57:35.921-0600|WARNING: Error in annotation processing: java.lang.NoClassDefFoundError: org/springframework/batch/core/configuration/annotation/BatchConfigurer 

Except that I am not referencing any of these missing classes anywhere in my project (other than those that Spring Boot itself can reference).

In addition, the application does not quite work as expected. If I click on RestController, then my page is displayed as I expect, but if I add any System.out or Logger.log statement to the controller method, this line of code will apparently never be executed; Apparently, this is simply skipped.

To demonstrate this problem, in my RestController sample application, I created a static counter. Then in the GET- / I method, increase this counter and System.out.println its value. I also return a value as part of the response.

And again, from the user's point of view, it seems that he is working: "Hello World" is displayed on the screen, and in brackets - the counter value. I am updating the window, the counter is incrementing. But nothing in the STS console. And if I go to the Glassfish magazine for the application, nothing will appear there either. Nothing. Nada. Zip. From what I can say, something mysteriously absorbs any attempt to record something.

To add to the puzzle, if I add System.out to SpringBootServletInitializer # configure (), it will do it in the console. But if I declare a constructor in my RestController and include System.out there, it does not get into the console. As an example, I even tried to include System.err in the constructor and Logger.getAnonymousLogger.severe in the method; none of these results will lead to anything.

It should be noted that it also deploys and runs as expected using an external Tomcat.

I would greatly appreciate any input, as it is unlikely that I will be able to convince my organization to deploy this to Tomcat or use the embedded Tomcat approach (due to the policy and overwhelming existing Glassfish environment).

My test project on Github is already here .

+5
source share
2 answers

The answer was given here: fooobar.com/questions/984648 / ...

There is a bug in Glassfish 3.1.X. You must include metadata-complete="true" in your root web.xml element.

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" metadata-complete="true" 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-app_3_1.xsd"> </web-app> 
+2
source

I had this problem with Payara 5, as I understand it, the problem became from Glassfish.

Versions: 1. Payara 5.192 2. Spring Boot 2.1.6

The solution worked for me:

I added this dependency to pom.xml.

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-batch</artifactId> <version>2.1.4.RELEASE</version> </dependency> 

My Glassfish-Web configuration:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"> <glassfish-web-app error-url=""> <class-loader delegate="true"/> <jsp-config> <property name="keepgenerated" value="true"> <description>Keep a copy of the generated servlet class' java code.</description> </property> </jsp-config> <!-- set a friendly context root --> <context-root>/players</context-root> <!-- Change the default character encoding from ISO-8859-1 to UTF-8 --> <parameter-encoding default-charset="UTF-8"/> </glassfish-web-app> 
0
source

Source: https://habr.com/ru/post/984651/


All Articles