-1
@Controller("/UserAction")
@RequestMapping("/greet.json")
public class UserAction extends BaseAction {

@RequestMapping(value = "/hello", method = RequestMethod.GET)

public void hello(HttpServletRequest request,HttpServletResponse response) {

    System.out.println("a");
}

@RequestMapping(value = "/word", method = RequestMethod.GET)

public void word(HttpServletRequest request,HttpServletResponse response) {


    System.out.println("123123@@@");
}

}

当我查看http://localhost:8080/ProjectName/greet.json/hellohttp://localhost:8080/ProjectName/greet.json/word 时无法执行 syso 方法

AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,businessService,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice,org.springframework.context.annotation。 ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; 工厂层次结构的根 08:33:38,490 错误 [org.springframework.web.servlet.DispatcherServlet] (org.springframework.web.servlet.FrameworkServlet:460) - 上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建错误在 ServletContext 资源 [/WEB-INF/web-config.xml] 中定义的名称为 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0' 的 bean:调用 init 方法失败;嵌套异常是java。lang.IllegalStateException:发现不明确的映射。无法将 'userAction' bean 方法 public void cn.elfsoft.controller.UserAction.word(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 映射到 {[/greet.json],methods=[],params =[],headers=[],consumes=[],produces=[],custom=[]}: 已经有 'userAction' bean 方法 public void cn.elfsoft.controller.UserAction.hello(javax.servlet.http .HttpServletRequest,javax.servlet.http.HttpServletResponse) 映射。

4

1 回答 1

0

我认为您有 2 个注释会混淆您的操作,请尝试仅使用以下注释:

@Controller
public class UserAction extends BaseAction {

@RequestMapping(value = "/greet.json/hello", method = RequestMethod.GET)

public void hello(HttpServletRequest request,HttpServletResponse response) {

    System.out.println("a");
}

@RequestMapping(value = "/greet.json/word", method = RequestMethod.GET)

public void word(HttpServletRequest request,HttpServletResponse response) {


     System.out.println("123123@@@");
}

如果您想使用控制器的公共路径,请添加到 @Controller("/commonPath")

然后在每种方法上使用

@RequestMapping("/specificEndPoint")
于 2016-03-25T14:53:08.577 回答