How to run Sprint boot Web application on Java 1.6 - java

I am working on a web project that using spring boot and maven.I am able to run my application on JAVA 1.8 successfully but when i try it to run on JAVA 1.6 i am facing issues.
My POM.XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>Demo_Web</artifactId>
<packaging>war</packaging>
<name>Demo_Web</name>
<description>Demo_Web</description>
<!-- <url> </url> -->
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<java.version>1.6</java.version>
<start-class>com.demo.boot.AppConfiguration</start-class>
</properties>
<dependencies>
<!-- Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Web with Tomcat + Embed -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
<!-- Optional, for bootstrap -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I have tried many site available on but not able to resolve
Can anyone help me with the pom.xml for spring boot that support java 1.6?

By default, Spring Boot 1.4.4.RELEASE requires Java 7 and Spring Framework 4.3.6.RELEASE or above. You can use Spring Boot with Java 6 with some additional configuration. See Section 81.11, “How to use Java 6” for more details. Explicit build support is provided for Maven (3.2+) and Gradle (1.12 or 2.x). Support for Gradle 2.8 and earlier is deprecated. Gradle 3 is not supported.
See the link
https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-system-requirements.html

Above answer is help but i want to add detailed changes that i made in my pom.xml to resolve my issue.
We just need to exclude jackson jar from dependency and in properties we have to set java version to 1.6.
Please refer my pom.xml to run spring boot in java 1.6.
<properties>
<!-- <servlet-api.version>3.0</servlet-api.version> -->
<java.version>1.6</java.version>
<tomcat.version>7.0.59</tomcat.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- need to add jackson 2.6 jars -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>

Related

Cannot resolve spring annotations in intellij idea

I downloaded jdk 11, and maven 3.6.3 and Itellj Idea and Import a project:
mvn clean install
But I always get this error:
Cannot resolve symbol 'SpringBootApplication'
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xxx.xxx.sofa</groupId>
<artifactId>sofa-spring-boot-pom-parent</artifactId>
<version>1.0.10</version>
</parent>
<properties>
<java.version>11</java.version>
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
<postgres.version>42.2.14</postgres.version>
<h2.version>1.4.200</h2.version>
<swagger.version>2.9.2</swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- DATABASE -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- OPTIONAL TOOLS -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I tried to delete the .idea folder or "invalid cache and restart" but nor the first neither the second approach fixed the problem.
There is a similar question Cannot resolve symbol SpringApplication but the answer didn't resolve my issue. how can I fix that?
Running the following command solved for me this issue :
mvn idea:idea
I fixed this issue by downgrading the maven version.
you seem to use Spring Boot version 1.0.1, #SpringBootApplication annotation was introduced in 1.2
You are not using SpringBoot parent but your own, you need to add dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
you need to add dependency
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Java eclipse does not recognize the import org.apache.poi package that is already imported with maven

I am trying to create an excel in java with apache poi, I am using spring boot and thymeleaf, I have already imported the dependencies in the pom.xml file and update it in my eclipse, the dependencies are in my project, when I run the command mvn clean install everything seems to be Okay, but when importing it to my java class, it can't find it, I already tried to change the version of the apache-poi library, but it didn't work. I leave here some reference data:
this is the class that I want to inport
eclipse does not recognize the jara apache-poi class
this is the code of my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>mx.com.telcel</groupId>
<artifactId>detalladoVentas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>detalladoVentas</name>
<description>Generación de reportes sisap</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId>
</dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId>
<scope>test</scope> </dependency -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- START Bibliotecas necesarias para el desarrollo de reportes en Excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.20</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
<scope>runtime</scope>
</dependency>
<!-- END Bibliotecas necesarias para el desarrollo de reportes en Excel -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
What do you think is the problem? I really appreciate your help.
I will answer my own question in case someone finds it useful in the future:
I didn't know what
< scope > runtime < /scope >
meant, now I see that this scope indicates that dependency is not required for compilation, but for execution.It is in the runtime and test classpaths, but not the compile classpath.
so the solution was to just remove this tag.
you need not to add scope of dependencies of Apache POI.
check it from here
https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml/4.1.2
I use them in gradle and their scope is compile time by default
https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml/4.1.2

What is causing java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z

Looking around at similar posts for this error, it seems that the issue comes from having incompatible versions of the same dependency. I have one project that calls a class from another, thus I have two separate pom.xml's, but both have the same version of the jackson dependency so I'm not sure what is causing this error. Here are my two pom.xml's:
pom.xml #1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.bingads</groupId>
<version>12.13.3</version>
<name>Bing Ads Java SDK</name>
<description>The Bing Ads Java SDK is a library improving developer experience when working with the Bing Ads services by providing high-level access to features such as Bulk API, OAuth Authorization and SOAP API.</description>
<url>https://github.com/BingAds/BingAds-Java-SDK</url>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.googlecode.jcsv</groupId>
<artifactId>jcsv</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${http.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${http.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.bingads</groupId>
<artifactId>microsoft.bingads</artifactId>
<version>12.13.3</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cxf.version>3.3.2</cxf.version>
<http.version>4.5.3</http.version>
</properties>
<artifactId>microsoft.bingads</artifactId>
</project>
and pom.xml #2
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.api-ads.examples</groupId>
<artifactId>adwords-axis-examples</artifactId>
<version>4.6.0</version>
<packaging>jar</packaging>
<name>AdWords Examples using Axis</name>
<description>
This project contains examples of using the Ads APIs client library for Java
with AdWords and the Apache Axis framework. Please see the README file for
more information about how to use the library.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<smokeMainClass>adwords.axis.v201809.basicoperations.GetCampaigns</smokeMainClass>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<!-- Ads client library dependencies -->
<dependency>
<groupId>com.google.api-ads</groupId>
<artifactId>ads-lib</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>com.google.api-ads</groupId>
<artifactId>adwords-axis</artifactId>
<version>4.6.0</version>
</dependency>
<!-- Third party dependencies -->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core --><!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<!-- Configuration to use log4j for logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>smoketest</id>
<properties>
<exec.mainClass>${smokeMainClass}</exec.mainClass>
</properties>
</profile>
</profiles>
</project>
When running each class separately, they both compile and run as intended, but when I call b.foo() from class a, I get the error in the title. Any ideas what is happening?
I poked around deeper through some of the dependencies and found that one was using a lower version of Jackson that you couldn't see on the surface. So if you have this problem and you're using Eclipse, view your pom.XML through the Dependencies Hierarchy view and you should be able to see where the incompatibility comes from.
You can maintain the parent module and other child modules integration using maven, and add the dependency in parent module so that should be consider by both child module.

SpringBoot Application GCP Deployment Issue

I am trying to deploy a GAE SpringBoot application on GCP but no luck.
Getting Below Error:
Uncaught exception from servlet
java.lang.RuntimeException: javax.servlet.ServletException: Not running on Jetty, JSR-356 support unavailable at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:68) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:330)
POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gcptest</groupId>
<artifactId>gcptest-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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-web</artifactId>
<!-- Excluded for GCP Conflict, as gcp runs on jetty -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</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>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- Dependency for GCP -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.48</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-6</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
</plugingcptest
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
<include>log4j2.json</include>
</includes>
</resource>
</resources>
</build>
</project>
You must convert your app to App Engine config. If you are using GOOGLE APP ENGINE standard, follow these steps:
Use the WAR packaging
You must use WAR packaging to deploy into Google App Engine Standard.
If you generate a Spring Boot project from start.spring.io, make sure you switch to the full version view of the initializer site, and select WAR packaging.
If you have an existing JAR packaging project, you can convert it into a WAR project by:
In pom.xml, change <packaging>jar</packaging> to <packaging>war</packaging>
Create a new SpringBootServletInitializer implementation:
public class ServletInitializer extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(YourApplication.class);
}
}
Remove Tomcat Starter
Google App Engine Standard deploys your WAR into a Jetty server. Spring Boot's starter includes Tomcat by default. This will introduce conflicts. Exclude Tomcat 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>
Do not include the Jetty dependencies. But you must include Servlet API dependency:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Add App Engine Standard Plugin
In the pom.xml, add the App Engine Standard plugin:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
</plugin>
This plugin is used to run local development server as well as deploying the application into Google App Engine.
Add App Engine Configuration
Add a src/main/webapp/WEB-INF/appengine-web.xml:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<version>1</version>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
</appengine-web-app>
This configure is required for applications running in Google App Engine.
Exclude JUL to SLF4J Bridge
Spring Boot's default logging bridge conflicts with Jetty's logging system. To be able to capture the Spring Boot startup logs, you need to exclude org.slf4j:jul-to-slf4j dependency. The easiest way to do this is to set the dependency scope to provided, so that it won't be included in the WAR file:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Out of memory errors
With Spring Boot >= 1.5.6, you may run into out of memory errors on startup. Please follow these instructions to work around this issue:
Inside src/main/resources, adding a logging.properties file with:
.level = INFO
Inside src/main/webapp/WEB-INF/appengine-web.xml, add a config that points to the new logging.properties file.
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties"/>
</system-properties>

NoSuchMethodError: org.apache.log4j.ConsoleAppender.<init>(Lorg/apache/log4j/Layout;)

I have a maven project with jdk: 1.8, spring-boot: 1.5.4.RELEASE, spring: 4.3.9.RELEASE, and some vendor dependencies. The project builds and runs but when I access resources used by vendor packages, I get following exception:
java.lang.NoSuchMethodError: org.apache.log4j.ConsoleAppender.<init>(Lorg/apache/log4j/Layout;)V
at bkLogPkg.SingletonLog.<init>(SingletonLog.java:19) ~[VendorComLib.jar:na]
at Vendor.ConnectionBasket.<init>(ConnectionBasket.java:31) ~[VendorServices.jar:na]
at Vendor.ConnectionBasketInterface.Loader(ConnectionBasketInterface.java:450) ~[VendorServices.jar:na]
at Vendor.ConnectionBasketInterface.<init>(ConnectionBasketInterface.java:251) ~[VendorServices.jar:na]
...
It's trying to call method from Vendor jar file to log4j 1.2.14.jar file, but it's unable to do it. I have added vendor dependencies in pom.xml file.
pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.sample</groupId>
<artifactId>angular2-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>angular2-spring</name>
<description>Angular 2 application with Spring 4</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<org.slf4j-version>1.2.14</org.slf4j-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</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-devtools</artifactId>
</dependency>
<!-- Vendor dependencies from Local Repository -->
<dependency>
<groupId>Vendor</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorServiceAuth</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorServices</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorComLib</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorHeaderClass</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I have the same issue today. It cost me several hours to find the reason.
You just have a conflict with your log4j jar.
The quick fix for this is :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
If you really need log4j, then add the dependency:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
You can check log4j-over-slf4j to know the detail.
I have encountered similar issues and all of mine were solved by making sure the version I was using was the most updated and that is is compatible with the rest of the code. With your problem, it looks as if the .jar is specifically built to be compatible so I doubt that's the issue. Only things I can think of given the information at hand is:
1.) Try making sure all .jar's being used are newest version. (Sometimes if your other .jar's are not completely updated, they can throw errors/exceptions when trying to access a method from a .jar that is a version ahead.)
2.) If "1" doesn't do it, try using a dependency import function in an IDE. I have had many occurrences where Maven was just causing odd errors from IDE compatibility. Importing all .jar's from a "Dependency" menu could also help.

Categories