【发布时间】:2014-12-05 14:03:11
【问题描述】:
我使用 Jersey 将一些统计数据公开为 REST 服务。 我正在使用 Weblogic
但是每次我执行请求以获取统计信息时 System.out.println("在构造后");被调用。
即使我在路径 @Stateless 旁边注释也会发生这种情况。
这就像 StorageService 在每个请求(req 范围)上实例化
有没有办法只调用一次初始化并避免在每个请求上创建 StorageService ?
@Path("/statistics")
public class StorageService {
@Context
private ServletContext application;
StatisticsStorage statisticsStorage;
@PostConstruct
public void initialize() {
System.out.println("In PostConstruct");
try {
statisticsStorage = new StatisticsStorage((String) application.getAttribute(AppProperties.PropKey.STATS_OUTPUT_PATH_PROP.toString()));
} catch (Exception sqle) {
sqle.printStackTrace();
}
}
@GET
// The Java method will produce content identified by the MIME Media type "text/plain"
@Produces({MediaType.APPLICATION_JSON})
public Domain getSnapshot() {}
谢谢
【问题讨论】:
标签: java jakarta-ee jersey weblogic jax-rs