Mavenアーキタイプを使用してサンプルのSpring-MVCアプリを作成しました
mvn archetype:generate -D groupId=test.tool -D artifactId=test-D version=0.1-SNAPSHOT -D archetypeArtifactId=spring-mvc-jpa-archetype -D archetypeGroupId=org.fluttercode.knappsack
私はURLからいくつかのパラメータを読み取ろうとしています:
package test.tool.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "/testReadRest", method = RequestMethod.GET)
public class TestReadRestController {
private static final Logger logger = LoggerFactory
.getLogger(TestReadRestController.class);
// No Params
@RequestMapping(method = RequestMethod.GET)
public void getMainModel(Model model) {
model.addAttribute("varFromClient","[NOT SET]");
model.addAttribute("tokenFromClient","[NOT SET]");
return;
}
// http://localhost:8080/test/testReadRest/varPost
// read "varPost"
@RequestMapping(value = "/{varPost}", method = RequestMethod.GET)
public void getVarFromURI(@PathVariable("varPost") String theVar, Model model) {
model.addAttribute("varFromClient",theVar);
model.addAttribute("tokenFromClient","[NOT SET]");
return;
}
}
しかし、試行時にパラメータが読み取られません
http://localhost:8080/test/testReadRest/varPost
代わりに、エラーが発生します。
Problem accessing /soctoolset/WEB-INF/views/testReadRest/varPost.jsp. Reason: NOT_FOUND
助言がありますか?
[編集]
これが豆です
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- Imports user-defined @Controller beans that process client requests -->
<beans:import resource="controllers.xml" />
</beans:beans>
およびcontroller.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Scans within the base package of the application for @Components to
configure as beans -->
<context:component-scan base-package="test.tool" />
<tx:annotation-driven />
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
</beans>