我已准备好成为一个新手问题,提前道歉!
我已经将我的项目从“先看看restful / spring”类型练习的示例重构为自定义应用程序。在某个地方,我已经移动/删除了对某事的引用,我现在遇到这样的编译错误:
/ C:/<> /src/main/java/resful/layer/MuliRestfulApplication.java:[9,8]无法访问javax.servlet.ServletException 找不到javax.servlet.ServletException的类文件
在Eclipse IDE中,我有一个市场陈述: - 无法解析类型javax.servlet.ServletContext。它是间接引用的 必需的.class文件 - 无法解析类型javax.servlet.ServletException。它是间接引用的 必需的.class文件
所以看起来我已经删除了对包含javax.servlet.XYZ的jar的引用。
如果我应该如何将Spring文件正确地添加到项目中以供Restful API应用程序使用,请有人指点我吗?我不确定是否应该在lib文件夹中添加jar,就像我以前使用POJO一样,因为Spring应用程序管理依赖关系的方式与我理解的不同。
我正在使用Maven来构建我的项目,我看到有很多罐子的m2文件夹,见下文:
由于stackoverflow警察FYI,我无法发布我的项目组织的图像。
并且非常感谢。
马特
这是我的pom.xml文件:
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>org.springframework</groupId>
<artifactId>gs-consuming-rest</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
这是我的Java类文件:
eclipse说,这是包装声明给我的错误 “无法解析类型javax.servlet.ServletException。它是从所需的.class文件间接引用的”package resfullayer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
@SpringBootApplication
public class MuliRestfulApplication extends SpringBootServletInitializer{
public static void main(String args[]) {
SpringApplication.run(MuliRestfulApplication.class, args);
}
// Used when deploying to a standalone servlet container
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MuliRestfulApplication.class);
}
}
这是我的build.gradle文件
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-consuming-rest'
version = '0.1.0'
}
apply plugin: 'war'
war {
baseName = 'muliRestfulApp'
version = '0.1.0'
}
task deployToTomcat(type: Copy) {
from war
into "C:/Users/Muli/Desktop/apache-tomcat-7.0.62/webapps"
}
repositories {
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-web")
compile("com.fasterxml.jackson.core:jackson-databind")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
这是堆栈跟踪:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-consuming-rest 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ gs-consuming-rest ---
[INFO] Deleting C:\Users\Muli\workspace\MuliAutomation\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gs-consuming-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Muli\workspace\MuliAutomation\src\main\resources
[INFO] skip non existing resourceDirectory C:\Users\Muli\workspace\MuliAutomation\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gs-consuming-rest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to C:\Users\Muli\workspace\MuliAutomation\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Muli/workspace/MuliAutomation/src/main/java/resfullayer/MuliRestfulApplication.java:[9,8] cannot access javax.servlet.ServletException
class file for javax.servlet.ServletException not found
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.588 s
[INFO] Finished at: 2015-06-16T21:18:43+00:00
[INFO] Final Memory: 14M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project gs-consuming-rest: Compilation failure
[ERROR] /C:/Users/Muli/workspace/MuliAutomation/src/main/java/resfullayer/MuliRestfulApplication.java:[9,8] cannot access javax.servlet.ServletException
[ERROR] class file for javax.servlet.ServletException not found
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
我还注意到堆栈跟踪会跳过2个不存在的资源目录。也许我已将此删除作为重构的一部分(/搞砸了)?如果可以,我可以将其添加回来/以某种方式生成它吗?