我的java应用程序启动了一个jetty服务器容器。
是否有任何“after init”方法,jetty可以在它启动后调用
将构造一个特定的BL对象并调用其中一个方法吗?
这是我的init码的代码:
public static void main(String[] args) throws Exception {
SdkServiceConfig.s.initLog();
logger.error("testing log");
final int port = 8083;
...
webappContext.setExtractWAR(false);
handlers.addHandler(webappContext);
// Adding the handlers to the server.
jettyServer.setHandler(handlers);
try {
jettyServer.start();
jettyServer.join();
} catch (Exception ex) {
logger.error("failed to init jetty server", ex);
System.out.println(ex);
throw new RuntimeException(ex);
} finally {
jettyServer.destroy();
}
}
然后我调用特定的url来触发我的服务器状态初始化。
Server.java
@Path("/waitRequests")
@GET
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void waitRequests() throws Exception {
System.out.println("waitRequests");
PubSubFactory pubSubFactory = new PubSubFactory();
pubSubFactory.init(SdkServiceConfig.s.GCP_PROJECT_ID, new File(SdkServiceConfig.s.SDK_PUBSUB_CLIENT_SECRET));
我希望它会像:
@Path("/sdk-service")
public class SdkOperation {
private final org.apache.log4j.Logger logger = LoggingUtils.getLogger();
private final CofmanService cofmanService;
// private SdkRequestRepo sdkRequestRepo;
private CustomPublisher resultPublisher;
public SdkOperation() throws Exception {
this(new CofmanServiceNet(), null);
}
Server server = new Server();
server.waitRequests()