在我的一个用例中,我想从 Spring Boot Rest API 的应用程序资源属性中传递多个参数,并且这些参数应该由注册的 ApplicationEventListener 或 Jersey 中的 ApplicationEvent 监听。有人可以建议我如何实现这一目标。下面是我的代码库
package com.learning;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.context.ConfigurableApplicationContext;
public class ABCApplication {
public static void main(String args[])
{
ConfigurableApplicationContext context =
SpringApplication.run(ABCApplication.class, args);
context.addApplicationListener(new ApplicationPidFileWriter());
context.addApplicationListener(new TestingListener());
}
}
这是我的监听器,它应该被触发并从 Rest API 接收这些参数。
import org.glassfish.jersey.server.monitoring.ApplicationEvent;
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
public class TestingListener implements ApplicationEventListener {
@Override
public void onEvent(ApplicationEvent event) {
if (event.getType() ==
ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) {
final ResourceModel resourceModel = event.getResourceModel();
final ResourceLogDetails logDetails = new
ResourceLogDetails();
resourceModel.getResources().stream().forEach((resource) -> {
logDetails.addEndpointLogLines(getLinesFromResource(resource));
});
logDetails.log();
}
}
附加我的资源
@Api
@Path("/resource")
public static class MyResource {
@GET
@Path("/get/path")
public String getMethod() {
return "get";
}
@POST
public void post(String entity) {
}
}
所以我期待的输出是
GET resource/get/path
POST resource
但这是我的业务逻辑,我想在这里获得更多应该来自应用程序资源属性文件的值。