我使用Jersey公開一些統計數據作爲REST服務。 我正在使用Weblogic@PostConstruct與Jersey 1.17一起使用,Weblogic
但是,每當我執行一個請求以獲取統計信息 System.out.println(「In PostConstruct」);叫做。
即使我在路徑@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() {}
感謝