我目前正在使用Spring编写API后端,我想使用Spring Boot部署到生产服务器上。
如果我在Eclipse中运行后端以编译为War(在Maven中指定),并使用Tomcat 7,则它可以正常运行。
但是,当我想部署到服务器时,我正在使用Spring Boot。
应用程序
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>
当我将整个项目复制到Linux服务器上并运行 maven package时 ,代码可以毫无问题地进行编译。然后,当我使用 java -jar
[文件名]
运行生成的jar文件时,出现以下错误:
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
我认为问题是因为我没有运行正确的Spring / Spring Boot版本(也许正在尝试使用不正确的Tomcat版本,所以该方法不存在?)
更新2015-04-06: 我尝试了kucing_terbang的使用spring boot v1.1.10的建议,但现在得到如下错误:
[Stacktrace deleted, as out of space for stackoverflow question, refer to stacktrace of v1.1.12.RELEASE below]
更新2015-04-07: 然后我尝试使用v1.1.12.RELEASE给出了类似的错误:
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
然后,我再次尝试了mvn clean and mvn软件包,这使我在编译时遇到以下错误:
[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]
但是,如果我使用v1.2.3.RELEASE,则不会得到编译错误,然后如果我更改为v1.1.12.RELEASE,并在不进行清理的情况下运行mvn软件包,我也不会收到该错误(但我得到了像以前一样运行jar时出错)。
也许这表明存在更深的问题?
任何有关此问题的帮助将不胜感激。
谢谢!
我试图在本地PC上运行您的代码,但出现了类似您所在位置的错误。而且,这些是我删除这些错误的步骤。
更新Spring Boot版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.12.RELEASE</version>
问题内容: 我的Maven依赖项出了什么问题。当我包含JPA时,我会列出pf例外 这是我的Maven依赖项 我的例外 和我的源代码 因此,我没有任何想法(不幸的是,没有示例)如何运行Spring boot和休眠两者。 问题答案: 您是否为数据源设置了或?这是一个例子: 有关可以在何处放置配置文件以及如何配置应用程序以处理任何目录中的属性文件的说明,请参阅此链接以获取更多信息。
问题内容: 我试图将Spring集成到具有数千个类的大型应用程序中,并且由于组件扫描,我在启动容器时遇到了巨大的延迟。 我已经将“基本软件包”中指定的目录数量缩小到最小,以减少扫描无关目录所浪费的时间,但是初始化的类路径扫描部分仍然需要大约1-2分钟。 那么,有没有一种方法可以优化扫描过程?我曾考虑过将候选类路径存储在文件中,然后使容器从文件中获取,而不是每次启动时都扫描类路径,但是我真的不知道从
问题内容: 我正在使用logback库在spring boot项目中实现日志记录。我想根据我的spring配置文件(属性“ spring.pofiles.active”)加载不同的日志记录配置文件。我有3个文件:logback-dev.xml,logback- inte.xml和logback-prod.xml。我正在使用Spring Boot版本1.2.2.RELEASE。 如您在Spring
问题内容: 我有以下Spring Security配置: 我期望以下逻辑:未经身份验证的用户将被重定向到。Spring会显示默认的Tomcat 403页面,而不是该页面。我也尝试过自定义,尽管没有成功。 如何在访问失败时实施自定义逻辑? 问题答案: AccessDeniedHandler仅适用于经过身份验证的用户。未经身份验证的用户的默认行为是重定向到登录页面(或适用于所使用的身份验证机制的任何内
问题内容: 在应用程序中,我可以使用以下命令指定自定义日志文件: 但是,如果我不指定一个,它会去哪儿? 我在以下任何文件夹中找不到它: 我 不 具备或任何其他日志记录的依赖。 我希望有类似的东西,因为默认配置运行嵌入式Tomcat: 问题答案: Spring Boot使用Commons Logging进行所有内部日志记录,但是使底层日志实现保持打开状态。 提供了Java Util Logging,
问题内容: 我是spring的新手,我使用https://start.spring.io/创建了一个新的spring boot项目,没有更多依赖关系,解压缩了zip文件并在IntelliJ IDEA中打开了该项目。我没有做任何进一步的配置。我现在正在尝试使用@PostConstruct方法设置bean-但是,该方法从未被spring调用。 这些是我的课程: SpringTestApplicatio