Spring 4 with Java Config and no xml -


i'm working on spring 4 based java application. application being deployed apache tomcat. application runs @ url of http://localhost:8080/test. can't get method defined in controller class run. i'm pretty sure it's configure issue. see doing wrong? work when run app @ root url of http://localhost:8080/, not option me. first class involved:

import org.springframework.web.servlet.support.abstractannotationconfigdispatcherservletinitializer;  public class testwebinitializer extends          abstractannotationconfigdispatcherservletinitializer {      @override     protected string[] getservletmappings() {         return new string[] { "/test" };     }      @override     protected class<?>[] getrootconfigclasses() {         return new class<?>[] { rootconfig.class };     }      @override     protected class<?>[] getservletconfigclasses() {         return new class<?>[] { webconfig.class };     } } 

2nd class involved:

import static org.springframework.web.bind.annotation.requestmethod.*; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod;  @suppresswarnings("unused") @controller @requestmapping({"/test"}) public class testcontroller {      @requestmapping(method=get)     public string home() {         //todo: convert system.out.println log4j              system.out.println("homecontroller.home()!");          return "home";     } } 

@hzpz correct, getservletmappings() controlls paths within application's context root gets handled servlet (instead of other servlets in same war). config matched bold part:

http://localhost:8080/context_root/test

to change context root, should change name of war (from root.war) or change config file of application server.

the application server strips matched portion of context root , servlet mapping pattern, if application correctly deployed app @ http://localhost:8080/test (i.e. context root of /test), servlets see path after /test, @requestmapping should handle "/".


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -