【问题标题】:how to create request type scope through annonation in spring mvc?如何通过spring mvc中的注释创建请求类型范围?
【发布时间】:2018-06-13 20:32:14
【问题描述】:

要求是我想要请求类型范围,特别是 bean Omsdashboard.java。我必须在每次请求我想要新对象时提交我想要的控制器架构。所以这可以通过请求范围来实现,因为控制器是默认情况下单身人士,为什么我不能处理这个问题,请解释一下。感谢您抽出宝贵的时间。 豆类 Omsdashborad.java

@Component
public class OMSDashBoard implements Serializable{

控制器类

我正在使用自动装配,但它们提供单例对象,但我想要另一个对象,当项目加载时,两个方法都调用 onload 时间首先调用下面的方法,然后调用第一个方法。

@Autowired
private WebApplicationContext context;
private OMSDashBoard omsDashBoard;

 public OMSDashBoard getOMSDashBoard() {
     System.out.println("@@2"+(OMSDashBoard) context.getBean("omsDashBoard"));
        return (OMSDashBoard) context.getBean("omsDashBoard");
    }
 @Autowired(required = false)
    public void setOmsDashBoard(@Qualifier("omsDashBoard") OMSDashBoard omsDashBoard) {
        this.omsDashBoard = omsDashBoard;

@RequestMapping(value = "/stuck/order/{fromDate}/{toDate}/{requestType}", method = RequestMethod.POST)
public ResponseEntity<OMSDashBoard> getAllStcukOrdersByRequestType(@PathVariable("fromDate") String fromDate,
        @PathVariable("toDate") String toDate, @PathVariable("requestType") String orderTypeCd) {
    return new ResponseEntity<OMSDashBoard>(omsDashBoard, HttpStatus.OK);
}


@RequestMapping(value = "order/summary/{fromDate}/{toDate}", method = RequestMethod.POST)
public ResponseEntity<OMSDashBoard> getOrderSummaryDetails(@PathVariable("fromDate") String fromDate,
        @PathVariable("toDate") String toDate) {
    return new ResponseEntity<OMSDashBoard>(omsDashBoard, HttpStatus.OK);
}

【问题讨论】:

  • 原型范围@Component @Scope("prototype") public class OMSDashBoard implements Serializable{}怎么样?
  • 我会尝试这个概念,但它的输出不工作我得到单例。我们只实现请求类型@AtaurRahmanMunna
  • 查看答案,stackoverflow.com/a/7621968/4423636 并让我知道状态。
  • 当我使用 scope("prototype") like-1091291254 hashcode 三次时,我得到了相同的哈希码,我在页​​面加载时得到了这个 id。
  • 你关注链接了吗?

标签: angularjs spring-mvc restful-architecture


【解决方案1】:

步骤: 在 omsdashboard.java 中使用 scope(value="request") 第2步 自动接线 公共 AnnotationConfigWebApplicationContext 上下文; 第三步 OMSDashBoard omsDashBoard = (OMSDashBoard) context.getBean(OMSDashBoard.class);在这两种方法中通过 bean 获取新对象。

【讨论】:

    猜你喜欢
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多