- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有没有办法在spring mvc中做到这一点;我想@Autowired RedirectAttributes:
@Controller
public class RegistrationController {
@Autowired private RedirectAttributes redirectAttributes;
@RequestMapping(value = SIGNUP_ROUTE, method = RequestMethod.POST)
public String signUpPage(ModelMap modelMap, User user) {
save(user);
redirectAttributes.addFlashAttribute("success", "Very good");
return "redirect:/sign-in";
}
}
我得到的异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.support.RedirectAttributes com.myhome.controller.RegistrationController.redirectAttributes; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.support.RedirectAttributes] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
最佳答案
在代码中注入(inject)依赖项的一种方法是添加类 RedirectAttributes 的额外参数
@Controller
public class RegistrationController {
@RequestMapping(value = SIGNUP_ROUTE, method = RequestMethod.POST)
public String signUpPage(ModelMap modelMap, RedirectAttributes rda, User user) {
save(user);
rda.addFlashAttribute("success", "Very good");
return "redirect:/sign-in";
}
}
关于java - 使用 RedirectAttributes 作为 bean spring mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37319126/
在 Spring Boot Controller 中,是否可以在其签名中没有 RedirectAttributes 的方法中访问 RedirectAttributes?换句话说,它可以作为“bean”
是否可以在签名中没有 RedirectAttributes 的情况下访问方法中的 RedirectAttributes?例如,当重写如下方法时: @Override public void onAut
目录 当controller层需要重定向到指定页面时,如何携带数据? RedirectAttributes的使用 RedirectAttributes存值后读取不
我在一个 Spring Webflux 应用程序上,我想在我的一个 Controller 上执行重定向: @Controller @RequestMapping(value = "/login") p
我写了这个方法: @RequestMapping(value="/someURL", method=GET) public String myMethod(RedirectAttributes red
我在 Controller 中的请求处理方法中添加 RedirectAttributes 时遇到此异常 - org.springframework.web.util.NestedServletExce
昨天我下载了新的 Spring 3.1RC 来测试刚刚引入的对 Spring MVC 中 flash 作用域变量的支持。不幸的是我无法让它工作...... 我有一个 HTML 表单,其中包含一些没有
到目前为止,我的理解是关于我们的 Controller 请求映射方法,我们可以指定 RedirectAttributes 参数并在请求被重定向时使用属性填充它。 示例: @RequestMapping
我有一个 Controller ,应该在处理后重定向到另一个端点,但它仅在我将 Activity 配置文件设置为 dev 时才起作用。当配置文件不是 dev 时, Controller 将返回登录页面
为了访问重定向方法中的重定向属性,我们利用模型的映射,如下所示: @Controller @RequestMapping("/foo") public class FooController {
感谢 Spring 3.1,我可以使用 RedirectAttributes.addFlashAttribute 使 Post/Redirect/Get 发生,但似乎有小问题 这是持久化表单对象的方法
我已阅读以下主题: Spring RedirectAttributes: addAttribute vs addFlashAttribute 据我了解,flash 属性和普通属性之间的主要区别在于普通
我是 Spring MVC 的新手。我正在使用 Spring 版本 4.1.6 并将我的两个 Web 应用程序 A 和 B 部署在用于开发环境的 tomcat 7 上。但在实际生产环境中,应用A会部署
有没有办法在spring mvc中做到这一点;我想@Autowired RedirectAttributes: @Controller public class RegistrationControl
我正在尝试在 Spring MVC 3.1-Release 中实现 RedirectAttributes 特性 我正在向 Post URL 发送简单的表单,并希望看到我在重定向中发送的值: 我的 Co
我的问题与这些类似: Testing Spring MVC annotation mapppings Testing Spring @MVC annotations 但是 给定一个 Controlle
我想用 RedirectAttibutes在 Spring 3.1 中出现的属性,我有以下处理程序方法用于在我的 Controller 中发布 @RequestMapping(value =
我正在使用: Spring 3.1 JUnit 4.10 我正在尝试为带有 RedirectAttributes 的 Controller 编写一个 junit 测试用例。 Controller 的签
@PostMapping("reduce_stock") public String reduceStockPost(@RequestParam("product_id") String produc
我正在使用: Spring 3.1 JUnit 4.10 我正在尝试为带有 RedirectAttributes 的 Controller 编写一个 junit 测试用例。 Controller 的签
我是一名优秀的程序员,十分优秀!