我的架构:
GlassFish Server Open Source Edition 3.1.2.2 (5)
Java EE 6
Eclipse IDE
我创建了一个 EJB 计时器,它打印一条日志消息:
@Startup
@Singleton
public class ProgrammaticalTimerEJB {
private final Logger log = Logger.getLogger(getClass().getName());
@Resource(name = "properties/mailconfig")
private Properties mailProperties;
@Resource
private TimerService timerService;
@PostConstruct
public void createProgrammaticalTimer() {
log.log(Level.INFO, "ProgrammaticalTimerEJB initialized");
ScheduleExpression everyTenSeconds = new ScheduleExpression().second("*/10").minute("*").hour("*");
timerService.createCalendarTimer(everyTenSeconds, new TimerConfig("passed message " + new Date(), false));
}
@Timeout
public void handleTimer(final Timer timer) {
log.info(new Date().toGMTString() + " Programmatical: " + mailProperties.getProperty("to"));
}
}
此类注入我的自定义 JNDI 资源:
@Resource(name = "properties/mailconfig")
private Properties mailProperties;
Eclipse 控制台:
INFO: 2 Aug 2013 10:55:40 GMT Programmatical: tim.herold@mylocal.de
INFO: 2 Aug 2013 10:55:50 GMT Programmatical: tim.herold@mylocal.de
INFO: 2 Aug 2013 10:56:00 GMT Programmatical: tim.herold@mylocal.de
Glassfish 设置
asadmin> get server.resources.custom-resource.properties/mailconfig.property
server.resources.custom-resource.properties/mailconfig.property.to=tim.herold@mylocal.de
Command get executed successfully.
asadmin>
现在我想在应用程序运行时更改此属性值。通过 Adminconsole 或 Asadmin 编辑它不起作用。这是可能的,还是有其他/更好的解决方案?
提前谢谢了