camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Talbut <jtal...@spudsoft.co.uk>
Subject Re: BeanFactory not initialized on second test
Date Thu, 10 May 2012 14:33:10 GMT
Hi,

Using Camel 2.9.2 and CXF 2.6.0.
Previously I was using Camel 2.5.5 (I think) and this was working.

I changed it to use a Spring @RunWith and that made no difference, then I noticed that client
was static.
When I changed that it started working.

I don't know why it wasn't working as a static, but it's working now.

Thanks.

Jim

On Thu, May 10, 2012 at 10:22:44PM +0800, Willem Jiang wrote:
> Hi
> 
> Which version of Camel are you using?
> If you want to reuse the ApplicationContext across the test, you can 
> add the below codes in you test
> public boolean isCreateCamelContextPerClass() {
>      return true;
> }
> 
> 
> On Thu May 10 18:53:01 2012, James Talbut wrote:
> > Hi,
> >
> > I'm getting an error of:
> > java.lang.IllegalStateException: BeanFactory not initialized or already closed -
call 'refresh' before accessing beans via the ApplicationContext
> > when my application context is created for the second time.
> >
> > The basics of the class are below.
> > When test1 is being run it works completely, but when test2 starts the line:
> > Select5ThingyStuffService service = new Select5ThingyStuffService();
> > throws the exception above.
> >
> > Is there a solution for this?
> >
> > Thanks
> > Jim
> >
> >
> > public class ThingyProcessorTest extends CamelSpringTestSupport
> > {
> >      private static final Logger log = LoggerFactory.getLogger( ThingyProcessorTest.class
);
> >      private static final String TARGET_URL = "http://localhost:9000/Select/Thingy/Stuff";
> >      private static Select5ThingyStuffPortType client;
> >
> >      @Override
> >      protected AbstractApplicationContext createApplicationContext() {
> >          FileSystemXmlApplicationContext localContext = new FileSystemXmlApplicationContext(
new String[] { "target/generated-resources/xml/xslt/Select5ThingyStuff-1.1.0.xml" }, true
);
> >          return localContext;
> >      }
> >
> >      @Override
> >      public void doPreSetup() throws Exception {
> >          super.doPreSetup();
> >
> >          Select5ThingyStuffService service = new Select5ThingyStuffService();
> >
> >          service.addPort( Select5ThingyStuffService.Select5ThingyStuffPort, SOAPBinding.SOAP11HTTP_BINDING,
TARGET_URL );
> >          client = service.getPort( Select5ThingyStuffPortType.class );
> >          BindingProvider binder = ( BindingProvider ) client;
> >          binder.getRequestContext().put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
TARGET_URL );
> >
> >          Client cl = ClientProxy.getClient(client);
> >          HTTPConduit http = (HTTPConduit) cl.getConduit();
> >          HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
> >          httpClientPolicy.setReceiveTimeout(0);
> >          http.setClient(httpClientPolicy);
> >      }
> >
> >      @Test
> >      public void test1() {
> >      }
> >
> >      @Test
> >      public void test2() {
> >      }
> > }
> >
> >
> 
> 
> 
> --
> Willem
> ----------------------------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> FuseSource
> Web: http://www.fusesource.com
> Blog:    http://willemjiang.blogspot.com (English)
>          http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
> Weibo: willemjiang
> 

Mime
View raw message