gpt4 book ai didi

java - Spring MVC 4.0 - 没有值的RequestMapping,方法名称的回退

转载 作者:行者123 更新时间:2023-12-02 06:21:49 28 4
gpt4 key购买 nike

所以我有这个 Controller 类,并且想使用方法名称作为请求映射值。我相信这曾经有效。

@Controller
@RequestMapping(value="start/*")
public class StartController extends BaseController {

@RequestMapping
@ResponseBody
public String home() {
return "{}";
}

@RequestMapping
@ResponseBody
public String test2() {
return "{}aaaaa" ;
}
}

但现在我收到此错误:

There is already 'startController' bean method
public java.lang.String mypackage.App.controllers.StartController.home() mapped.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'startController' bean method
public java.lang.String mypackage.App.controllers.StartController.test2()
to {[/start],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'startController' bean method
public java.lang.String mypackage.App.controllers.StartController.home() mapped.
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:643)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:606)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:657)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:525)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)

看来我只能有一个默认的索引请求映射。

我错过了什么?

最佳答案

根据 Spring 文档,自 Spring 3.1 以来,这不再可能:

还有一些事情不再可能:

Rely on method names as a fall-back mechanism to disambiguate between two @RequestMapping methods that don't have an explicit path mapping URL path but otherwise match equally, e.g. by HTTP method. In the new support classes @RequestMapping methods have to be mapped uniquely.

See Documentation

关于java - Spring MVC 4.0 - 没有值的RequestMapping,方法名称的回退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20947841/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com