Fisrt,我需要说我正在使用会话作用域bean。因此,在会话关闭之前,将调用preDestroy()方法
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "session")
public class MySessionBean {
@PreDestroy
public void preDestroy() {
//Do Smth with using Security principal
}
}
当我使用 Security注销时,一切正常,则调
在WebLogic10.3.4.0(EJB3.0)上,当我停止应用程序时,我想要在EJB无状态的predestroy阶段清除计时器。
但是weblogic提出了这条消息
java.lang.IllegalStateException: [EJB:010193]Illegal call to EJBContext method. The bean is in "null" state. It cannot perform 'getting the Timer Service' action(s). Refer to the EJB specification fo
如何在部署在通配符上的war容器中实现能够优雅关闭的服务?我有以下示例代码:
SomeService.java:
@Stateless
public class SomeService {
public void doThing() {
// this will fail once the component is shut down.
System.out.println("Doing some work...");
}
}
SomeWorker.java:
@Singleton
@Startup
public class So
我有一个要添加ServletContextListener接口的现有类:
@Service
public class MyService {
//...
}
@Component
public class MyController {
@Autowired
private MyService service;
}
这个没问题。但是,一旦我添加了public class MyService implements ServletContextListener,那么我就会在MyController上得到以下错误
org.springframework.beans.facto
实际问题
我正在尝试用Jersey2.0创建一个简单的JAX Application,如下所示:
@ApplicationPath("")
public class MyService extends ResourceConfig {
public MyService() {
packages(MyService.class.getPackage().getName());
register(new ApplicationBinder());
}
private static class ApplicationBinder extends A
我使用Java 5。我为所有EJB编写了一个拦截器,它有三种日志记录方法:
public class DefaultInterceptor {
public static final String PREFIX = "!!!!!!!!!Interceptor:";
@PostConstruct
public void postConstruct(InvocationContext ctx) {
try {
System.out.println(PREFIX + " postConstruct");
我正在开发简单的java代码(没有bean或容器框架),我想实现@PostConstruct / @PreDestroy功能。这有可能吗?
我编写了一个示例代码来检查可行性(下面的代码示例)。但是postContruct()和beforeDestroy()方法没有被调用。
如何实现这一点?
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
public class Test {
public static void main (String...strings) {
我是Spring Boot的新手,我有一个Spring Boot应用程序,它似乎忽略了@PreDestroy注释-当我从命令行或通过Eclipse运行时,我从来没有看到@PreDestroy代码在应用程序关闭时运行(例如通过ctrl-c)。
代码如下...
Application.java:
@SpringBootApplication
public class Application {
@Autowired
private MessageProcessor messageProcessor;
public static void main(String[] ar
在我的Spring应用程序中,有一个用于执行某些任务的调度器。这里没有使用调度注释,因为调度非常复杂-它是动态的,并且使用了数据库中的一些数据。因此,使用了带有线程休眠的简单的无限循环。并根据一定的规则改变休眠间隔。也许所有这些都可以使用Scheduled注解来完成,但问题不在于此。
下面是一个简单的例子:
@Service
public class SomeService {
@PostConstruct
void init() {
new Thread(() -> {
while (true) {
在一个使用JSF2和Ajax的简单演示web应用程序中,ManagedBean中有一个从JMS队列接收消息的方法:
@ManagedBean
public class Bean {
@Resource(mappedName = "jms/HabariConnectionFactory")
private ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/TOOL.DEFAULT")
private Queue queue;
public S