我正在尝试使用gradle编译war文件以部署到JBoss 7.1 AS,但它无法编译(无法找到ServletContext)....
请参阅下面的gradle.build。
错误:
/workspace/AgileRunner/src/main/java/com/agilerunner/web/config/AgileRunnerApplicationInitializer.java:20:找不到符号 symbol:方法addListener(org.springframework.web.context.ContextLoaderListener) location:接口javax.servlet.ServletContext servletContext.addListener(new ContextLoaderListener(rootContext)); ^ /workspace/AgileRunner/src/main/java/com/agilerunner/web/config/AgileRunnerApplicationInitializer.java:22:找不到符号 symbol:方法addServlet(java.lang.String,org.springframework.web.servlet.DispatcherServlet) location:接口javax.servlet.ServletContext ServletRegistration.Dynamic dispatcher = servletContext.addServlet(“dispatcher”,new DispatcherServlet(rootContext)); ^ 2个错误 :compileJava FAILED
gradle.build:
apply plugin:'eclipse'
apply plugin:'war'
apply plugin:'cargo'
repositories {
mavenCentral()
}
dependencies {
def cargoVersion = '1+'
cargo 'org.codehaus.cargo:cargo-core-uberjar:$cargoVersion',
'org.codehaus.cargo:cargo-ant:$cargoVersion',
'org.jboss.as:jboss-as-controller-client:7.1+'
providedCompile 'javax.servlet:servlet-api:2+',
'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1+',
'org.jboss.as:jboss-as-controller-client:7.1+'
compile 'org.springframework:spring-context:4+',
'org.springframework:spring-webmvc:4+',
'org.thymeleaf:thymeleaf:2+',
'org.thymeleaf:thymeleaf-spring4:2+',
'log4j:log4j:1+'
testCompile 'junit:junit:4+'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0+'
}
}
cargo {
containerId = 'jboss71x'
port = 8080
remote {
hostname = '127.0.0.1'
}
}
感谢您的帮助。
ý。
答案 0 :(得分:0)
请尝试更改您的servlet-api依赖
来自:'javax.servlet:servlet-api:2+'
至:'javax.servlet:javax.servlet-api:3.0.1'
JEE6之前的ServletContext
(Servlet规范3.0)没有注册监听器的API机制。
此外,'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1+'
应为providedRuntime
(如果有)。这可能是您在IDE中没有错误但是确实使用了gradle编译