如何通过 spring mvc 中的注释创建请求类型范围?

how to create request type scope through annonation in spring mvc?

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

@Component
public class OMSDashBoard implements Serializable{

控制器class

我正在使用 autowire,但他们给出了单例对象,但我想要另一个对象,当项目加载时,这两个方法调用 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);
}

步骤: 在 omsdashboard.java 中使用范围(值="request") 第2步 自动装配 public AnnotationConfigWebApplicationContext上下文; 第三步 OMSDashBoard omsDashBoard = (OMSDashBoard) context.getBean(OMSDashBoard.class);在这两种方法中都通过bean获取新对象。