|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2007 the original author or authors. |
| 2 | + * Copyright 2002-2009 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 |
|
24 | 24 | import org.springframework.beans.factory.DisposableBean;
|
25 | 25 | import org.springframework.beans.factory.InitializingBean;
|
| 26 | +import org.springframework.context.ApplicationEvent; |
| 27 | +import org.springframework.context.ApplicationListener; |
26 | 28 | import org.springframework.context.Lifecycle;
|
| 29 | +import org.springframework.context.event.ContextRefreshedEvent; |
27 | 30 |
|
28 | 31 | /**
|
29 | 32 | * Generic bean that manages JCA 1.5 message endpoints within a Spring
|
|
144 | 147 | * @see javax.resource.spi.endpoint.MessageEndpointFactory
|
145 | 148 | * @see javax.resource.spi.ActivationSpec
|
146 | 149 | */
|
147 |
| -public class GenericMessageEndpointManager implements InitializingBean, Lifecycle, DisposableBean { |
| 150 | +public class GenericMessageEndpointManager |
| 151 | + implements ApplicationListener<ApplicationEvent>, Lifecycle, InitializingBean, DisposableBean { |
148 | 152 |
|
149 | 153 | private ResourceAdapter resourceAdapter;
|
150 | 154 |
|
@@ -209,8 +213,8 @@ public ActivationSpec getActivationSpec() {
|
209 | 213 | }
|
210 | 214 |
|
211 | 215 | /**
|
212 |
| - * Set whether to auto-start the endpoint activation along with |
213 |
| - * this endpoint manager's initialization. |
| 216 | + * Set whether to auto-start the endpoint activation after this endpoint |
| 217 | + * manager has been initialized and the context has been refreshed. |
214 | 218 | * <p>Default is "true". Turn this flag off to defer the endpoint
|
215 | 219 | * activation until an explicit {#start()} call.
|
216 | 220 | */
|
@@ -242,8 +246,13 @@ else if (activationSpec.getResourceAdapter() != getResourceAdapter()) {
|
242 | 246 | throw new IllegalArgumentException("ActivationSpec [" + activationSpec +
|
243 | 247 | "] is associated with a different ResourceAdapter: " + activationSpec.getResourceAdapter());
|
244 | 248 | }
|
| 249 | + } |
245 | 250 |
|
246 |
| - if (this.autoStartup) { |
| 251 | + /** |
| 252 | + * Start upon a ContextRefreshedEvent if the 'autoStartup' property value is "true". |
| 253 | + */ |
| 254 | + public void onApplicationEvent(ApplicationEvent event) { |
| 255 | + if (event instanceof ContextRefreshedEvent && this.autoStartup) { |
247 | 256 | start();
|
248 | 257 | }
|
249 | 258 | }
|
|
0 commit comments