J'écris actuellement un backend d'API utilisant Spring que je souhaite déployer sur un serveur de production utilisant Spring Boot.
Si j'exécute le backend dans Eclipse en compilant une guerre (spécifiée dans Maven), et en utilisant Tomcat 7, il s'exécute sans problème.
Cependant, comme je veux déployer sur le serveur, j'utilise Spring Boot.
Application.Java
package com.ninjasquare.server;
import Java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("NinjaSquare server up and running with Spring Boot!");
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ninjasquare</groupId>
<artifactId>NinjaSquareServer</artifactId>
<!-- Server Deployment Change Required: 1. Change war to jar -->
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<!-- Spring Boot related config -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<properties>
<Java-version>1.7</Java-version>
<!-- Note: By default Spring Boot uses Tomcat 8. We set this so we can use Tomcat 7. -->
<!-- <Tomcat.version>7.0.59</Tomcat.version> -->
<!-- <org.springframework-version>4.1.6.RELEASE</org.springframework-version> -->
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
<jersey.version>1.8</jersey.version>
<org.springframework.data.version>2.2.0.RELEASE</org.springframework.data.version>
<org.springframework.spring-test>2.5</org.springframework.spring-test>
<log4j.version>1.2.15</log4j.version>
<javax.inject.version>1</javax.inject.version>
<javax.servlet.version>3.0.1</javax.servlet.version>
<javax.servlet.jsp.version>2.1</javax.servlet.jsp.version>
<javax.servlet.jstl.version>1.2</javax.servlet.jstl.version>
<spring-social-facebook-version>1.1.1.RELEASE</spring-social-facebook-version>
<junit.version>4.4</junit.version>
<cglib.version>2.2.2</cglib.version>
<org.hibernate.version>4.3.1.Final</org.hibernate.version>
<com.github.jsimone.version>7.0.22.3</com.github.jsimone.version>
<org.neo4j.app.version>1.8.2</org.neo4j.app.version>
<spring-data-neo4j.version>2.0.1.RELEASE</spring-data-neo4j.version>
<maven-Eclipse-plugin.version>2.9</maven-Eclipse-plugin.version>
<org.Apache.maven.plugins.version>2.5.1</org.Apache.maven.plugins.version>
<org.codehaus.mojo>1.2.1</org.codehaus.mojo>
<org.Apache.maven.plugins.maven-dependency-plugin>2.4</org.Apache.maven.plugins.maven-dependency-plugin>
<org.Apache.maven.plugins.maven-surefire-plugin>2.6</org.Apache.maven.plugins.maven-surefire-plugin>
</properties>
<dependencies>
<!-- Server Deployment Change Required: 2. Include our custom JAR. For now, patch this code on the server manually.
Note: This JAR needs to be installed with maven install:install-file on the server -->
<!--
<dependency>
<groupId>com.ninjasquare.common</groupId>
<artifactId>ninjasquarecommon</artifactId>
<version>0.01</version>
</dependency>
-->
<!-- Spring Boot dependency -->
<!-- Import dependency management from Spring Boot -->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.2.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Was this code missing before? -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<!-- Jackson/Jersey deps -->
<dependency>
<groupId>com.Sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.Sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.Sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- SDN -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<!-- <version>${org.springframework.data.version}</version> -->
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<!-- <version>${org.springframework.spring-test}</version> -->
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<!-- <version>${org.springframework-version}</version> -->
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<!-- <version>${org.springframework-version}</version> -->
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<!-- <version>${org.aspectj-version}</version> -->
</dependency>
<!-- Logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<!-- <version>${log4j.version}</version> -->
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.Sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.Sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>${javax.inject.version}</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!-- <version>${javax.servlet.version}</version> -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${javax.servlet.jsp.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<!-- <version>${javax.servlet.jstl.version}</version> -->
</dependency>
<!-- Import Spring Social libraries -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<!-- <version>${spring-social-facebook-version}</version> -->
</dependency>
<!-- additional libraries required by neo/spring... -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- <version>${junit.version}</version> -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<!-- <version>${org.hibernate.version}</version> -->
</dependency>
<!-- execute immediately support... -->
<dependency>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>${com.github.jsimone.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.Sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>${org.neo4j.app.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<classifier>static-web</classifier>
<version>${org.neo4j.app.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<version>${spring-data-neo4j.version}</version>
</dependency> -->
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Plugin for Spring Boot Maven -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-Eclipse-plugin</artifactId>
<!-- <version>${maven-Eclipse-plugin.version}</version> -->
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.Eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.Eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.Apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>${org.Apache.maven.plugins.version}</version> -->
<configuration>
<source>${Java-version}</source>
<target>${Java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<!-- <version>${org.codehaus.mojo}</version> -->
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
<!-- enable execution environment... -->
<!-- <plugin>
<groupId>org.Apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${org.Apache.maven.plugins.maven-dependency-plugin}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>${com.github.jsimone.version}</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin> -->
<!-- get Spring, Maven & JUnit test working... -->
<plugin>
<groupId>org.Apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- <version>${org.Apache.maven.plugins.maven-surefire-plugin}</version> -->
<dependencies>
<dependency>
<groupId>org.Apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${org.Apache.maven.plugins.maven-surefire-plugin}</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>**/testcases/*.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Lorsque je copie l'intégralité du projet sur mon serveur Linux et que je lance maven package , le code est compilé sans problème. Lorsque j’exécute ensuite le fichier jar généré avec Java -jar [nom du fichier] j’obtiens l’erreur suivante:
09:17:26.946 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is Java.lang.NoSuchMethodError: org.Apache.Tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/Apache/Tomcat/JarScanFilter;)V
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:133) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:474) ~[spring-context-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:118) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:686) [spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:320) [spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:957) [spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:946) [spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at com.ninjasquare.server.Application.main(Application.Java:13) [NinjaSquareServer-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_75]
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57) ~[na:1.7.0_75]
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.7.0_75]
at Java.lang.reflect.Method.invoke(Method.Java:606) ~[na:1.7.0_75]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:53) [NinjaSquareServer-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at Java.lang.Thread.run(Thread.Java:745) [na:1.7.0_75]
Caused by: Java.lang.NoSuchMethodError: org.Apache.Tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/Apache/Tomcat/JarScanFilter;)V
at org.springframework.boot.context.embedded.Tomcat.SkipPatternJarScanner$Tomcat8TldSkipSetter.setSkipPattern(SkipPatternJarScanner.Java:106) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.Tomcat.SkipPatternJarScanner.setPatternToTomcat8SkipFilter(SkipPatternJarScanner.Java:61) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.Tomcat.SkipPatternJarScanner.<init>(SkipPatternJarScanner.Java:56) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.Tomcat.SkipPatternJarScanner.apply(SkipPatternJarScanner.Java:87) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.Java:168) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.Java:154) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.Java:157) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:130) ~[spring-boot-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
... 13 common frames omitted
Je pense que le problème est dû au fait que je n'ai pas les bonnes versions de Spring/Spring Boot en cours d'exécution (peut-être tente-t-il d'utiliser une version incorrecte de Tomcat pour que la méthode n'existe pas?)
Update 2015-04-06: J'ai suivi la suggestion de kucing_terbang d'utiliser la version 1.1.10 de Spring Boot, mais j'obtiens maintenant l'erreur comme suit:
[Stacktrace deleted, as out of space for stackoverflow question, refer to stacktrace of v1.1.12.RELEASE below]
Update 2015-04-07: J'ai ensuite essayé avec v1.1.12.RELEASE qui donnait des erreurs similaires:
07:41:29.917 [main] INFO o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
07:41:29.949 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:124) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:476) ~[spring-context-4.0.9.RELEASE.jar!/:4.0.9.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:109) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:691) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:320) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:952) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:941) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at com.ninjasquare.server.Application.main(Application.Java:13) [NinjaSquareServer-0.0.1-SNAPSHOT.jar!/:na]
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_75]
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57) ~[na:1.7.0_75]
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.7.0_75]
at Java.lang.reflect.Method.invoke(Method.Java:606) ~[na:1.7.0_75]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:53) [NinjaSquareServer-0.0.1-SNAPSHOT.jar!/:na]
at Java.lang.Thread.run(Thread.Java:745) [na:1.7.0_75]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.Java:174) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.Java:147) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:121) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
... 13 common frames omitted
07:41:29.952 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:124) ~[spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:476) ~[spring-context-4.0.9.RELEASE.jar!/:4.0.9.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:109) ~[spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:691) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:320) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:952) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:941) [spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at com.ninjasquare.server.Application.main(Application.Java:13) [NinjaSquareServer-0.0.1-SNAPSHOT.jar!/:na]
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_75]
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57) ~[na:1.7.0_75]
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.7.0_75]
at Java.lang.reflect.Method.invoke(Method.Java:606) ~[na:1.7.0_75]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:53) [NinjaSquareServer-0.0.1-SNAPSHOT.jar!/:na]
at Java.lang.Thread.run(Thread.Java:745) [na:1.7.0_75]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.Java:174) ~[spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.Java:147) ~[spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:121) ~[spring-boot-1.1.12.RELEASE.jar!/:1.1.12.RELEASE]
... 13 common frames omitted
J'ai ensuite essayé à nouveau un paquet mvn clean et mvn, ce qui m'a donné l'erreur suivante lors de la compilation:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[6,46] cannot find symbol
symbol: class SpringBootApplication
location: package org.springframework.boot.autoconfigure
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[9,2] cannot find symbol
symbol: class SpringBootApplication
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[6,46] cannot find symbol
symbol: class SpringBootApplication
location: package org.springframework.boot.autoconfigure
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[9,2] cannot find symbol
symbol: class SpringBootApplication
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.839s
[INFO] Finished at: Tue Apr 07 07:31:41 BST 2015
[INFO] Final Memory: 24M/63M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project NinjaSquareServer: Compilation failure: Compilation failure:
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[6,46] cannot find symbol
[ERROR] symbol: class SpringBootApplication
[ERROR] location: package org.springframework.boot.autoconfigure
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[9,2] cannot find symbol
[ERROR] symbol: class SpringBootApplication
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[6,46] cannot find symbol
[ERROR] symbol: class SpringBootApplication
[ERROR] location: package org.springframework.boot.autoconfigure
[ERROR] /home/dengke/test_garden/NinjaSquareServer-DS-ServerDeploymentPOC-2015-04-04/src/main/Java/com/ninjasquare/server/Application.Java:[9,2] cannot find symbol
[ERROR] symbol: class SpringBootApplication
[ERROR] -> [Help 1]
Cependant, si j'utilise v1.2.3.RELEASE, je ne reçois pas l'erreur de compilation, et si je passe ensuite à v1.1.12.RELEASE et exécute le package mvn sans un nettoyage, je n'obtiens pas non plus l'erreur erreur lors de l’exécution du pot comme auparavant).
Peut-être cela indique-t-il un problème plus profond?
Toute aide concernant ce problème serait grandement appréciée.
Merci!
J'ai essayé d'exécuter votre code dans mon ordinateur local et il y avait une erreur semblable à ce qui s'est passé à votre place. Et, ce sont les étapes que j'ai faites pour éliminer ces erreurs.
Mettre à jour la version de démarrage du printemps
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.12.RELEASE</version>
</parent>
Mettez à jour votre classe principale en tant que l'annotation @SpringBootApplication
n'existe qu'après la version 1.2.0 de Spring Boot.
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("NinjaSquare server up and running with Spring Boot!");
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
Supprimez la dépendance "webapp-runner
" de pom.xml
car cette bibliothèque possède également la classe org.Apache.catalina.core.StandardContext
qui était en conflit avec celle de la bibliothèque intégrée Tomcat.
<dependency>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>${com.github.jsimone.version}</version>
<scope>provided</scope>
</dependency>
Oui, supprimez ces lignes;)
Exécuter l'application et ensuite, profiter?
J'ai eu exactement le même problème avec Spring boot
et le embedded Tomcat server
.
Après de nombreuses heures dehit et trial, exécuter et relanceri s'est avéré quei avait initialement ajouté un serveur Tomcat local à mon projet, qui était en conflit avec le serveur Tomcat intégré fourni par Spring Boot
. Après avoir supprimé le serveur Tomcat du chemin de génération des projets, exécuter Spring Boot
était un véritable charme.
Faites un clic droit sur le projet
Build Path --> Configure Build Path --> Libraries(Tab)
et supprimez l’exécution de votre serveur Tomcat si vous en avez ajouté un par erreur. Vous devriez être prêt à partir maintenant.
J'ai eu l'erreur parce que j'ai copié certains fichiers jar du dossier lib de Tomcat vers le dossier lib de jdk. Ainsi, il possède une version incompatible de Tomcat sur le chemin d'accès aux classes. J'ai résolu ce problème après la réinstallation de jdk.
Cette erreur m’est arrivée parce que j’ai créé un projet Maven en utilisant l’archétype de la webapp.
Recréer le projet comme un simple projet Maven a résolu ce problème.
Mon erreur a été résolue en changeant la version 9 d'Apache Tomcat en version 8.5 non prise en charge par Spring Boot 1.5.