cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Spring context that is already running?

raarm
Champ in-the-making
Champ in-the-making
Hi everyone,

I use this code in my application:

ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
authenticationService.authenticate("admin", "admin".toCharArray());
………..
       

when I compile this code occur a exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [alfresco/core-services-context.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
Caused by: java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]

I don´t wanna stop my Alfresco server!!! I think that……I need to get the instance or registry that is already running…..How to get this context?? Today my application is running in the same localhost that Alfresco server but I want to use this code in applets.

Thanks :roll:
1 REPLY 1

pmonks
Star Contributor
Star Contributor
Spring application contexts are only available in the same JVM (and in most cases classloader) that they're created in.  In other words you can only access the Alfresco context from code that's running within the Alfresco web client web app.  Note that this has nothing to do with Alfresco - it's simply the way Spring works.

If you wish to access Alfresco functionality out-of-process (from other web apps, an applet, another JVM etc. etc.), take a look at the various remote APIs, including:
1. web scripts
2. the SOAP API
3. JCR-RMI
4. AVM remote (for simple interactions with web projects)