【发布时间】:2016-07-30 14:11:48
【问题描述】:
我的弹簧靴有问题。 它将数据保存在一个被注释的类中:
@RestController、@Service、@Component。
我无法保留任何数据,因为它会像会话一样与其他人共享。
例子:
@RestController
public class controller {
int x = 65;
@RequestMapping(value = "/set/{number}", method = RequestMethod.GET)
public int view(@PathVariable("number") int number) {
x = number;
return x;
}
@RequestMapping(value = "/get", method = RequestMethod.GET)
public int view2() {
return x;
}
}
第一次调用: localhost:80802/get 结果:65。
第二次通话: localhost:8080/set/5 结果:5
第三次调用: localhost:8080/get Result:5
第三次调用结果假定为:65
这种情况也发生在我提到的其他注释中。
为什么它使用@RestController 类作为一种单例? 我无法在带注释的类中存储任何内容?
谢谢。
【问题讨论】:
标签: spring-boot annotations spring-restcontroller spring-boot-maven-plugin