spring - WebMVC mapping .jsp Java-Based-Configuration without @ComponentScan -
i utilize spring's java-based-configuration in project hello.
this configuration:
@configuration @enablewebmvc public class config{ @scope("session") public a(){ homecoming new a(); } } this web.xml
<web-app> <servlet> <servlet-name>world</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>world</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> </web-app> this class a
@controller public class a{ @requestmapping("test.html") public string foo(){ homecoming "bar"; } } this file bar.jsp:
abc this pom.xml:
... <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>4.1.1.release</version> </dependency> ... anyway, if request http://localhost/hello/test.html blank page instead of abc , output:
dispatcherservlet name 'world' processing request [/hello/test.html] looking handler method path /test.html did not find handler method [/test.html] no mapping found http request uri [/hello/test.html] in dispatcherservlet name 'world'
i missed @bean @ config.
@configuration @enablewebmvc public class config{ @bean @scope("session") public a(){ homecoming new a(); } } and foo must this:
public string foo(){ homecoming "bar.jsp"; } java spring jsp maven
No comments:
Post a Comment