【发布时间】:2016-03-21 16:02:15
【问题描述】:
不确定我在这里缺少什么......
样品控制器:
@Controller
@RequestMapping(value="/schedule/*")
public class ScheduleController {
@RequestMapping(value="/job", method=RequestMethod.GET)
@ResponseBody
public String test(@RequestParam (value = "name", required = false) String name) throws Exception{
System.out.println("name:" + name);
return "Yes, I got it, " + name;
}
}
web.xml
<display-name>JS</display-name>
<!-- Spring MVC -->
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/WEB-INF/spring/js-rest.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
js-rest.xml 文件
<context:component-scan base-package="com.test.js.controller"> </context:component-scan>
<context:annotation-config />
分级:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'org.springframework:spring-core:3.0.5.RELEASE'
compile 'org.springframework:spring-beans:3.0.5.RELEASE'
compile 'org.springframework:spring-context:3.0.5.RELEASE'
compile 'org.springframework:spring-webmvc:3.0.5.RELEASE'
compile 'org.springframework:spring-aop:3.0.5.RELEASE'
compile 'org.springframework:spring-web:3.0.5.RELEASE'
providedCompile 'javax.servlet:servlet-api:2.5'
runtime 'javax.servlet:jstl:1.1.2'
}
jettyRunWar.contextPath = ''
控制器位于src\main\java\com\test\js\controller 文件夹中
web.xml 在 src\main\webapp\WEB-INF\ 文件夹中
js-rest.xml 在 src\main\webapp\WEB-INF\spring\ 文件夹中
试过了
localhost:8080\schedule\job
localhost:8080\<projectname>\schedule\job
localhost:8080\job
localhost:8080\<project-name>\job
我得到的只是 404 Not found。
我这里有什么遗漏吗?
【问题讨论】:
标签: spring rest model-view-controller gradle http-status-code-404