Getting Application Context from a webservice

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2010 12:18 PM
Hey, im using the kofax plugin Ascent, and i need to add a property to a node inside DbNodeServiceImpl. That property is stored in my database. But to access tables in the database i was using this
Unfortunatly, i cant get the ApplicationContext that way when i use the plugin, i also tried:
Am i going for the wrong approach?
protected static ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
to get the proper context.Unfortunatly, i cant get the ApplicationContext that way when i use the plugin, i also tried:
protected static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); protected static ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml"); protected static ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:alfresco/jcr-context.xml"); protected static ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:alfresco/hibernate-context.xml");
Am i going for the wrong approach?
Labels:
- Labels:
-
Archive
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2010 12:35 PM
To anyone with a similar problem, the solution is this:
add a line similar to this to your application-context.xml in the classes directory
<bean id="appContext" class="your.package.and.class.name.in.repository"></bean>
your.package.and.class.name.in.repository = something like "org.MyClass"
create that class making sure it implements "ApplicationContextAware"
make a getter, can be static, and use it to get the applicationContext whenever you need it.
Hope it helps someone.
Regards
add a line similar to this to your application-context.xml in the classes directory
<bean id="appContext" class="your.package.and.class.name.in.repository"></bean>
your.package.and.class.name.in.repository = something like "org.MyClass"
create that class making sure it implements "ApplicationContextAware"
make a getter, can be static, and use it to get the applicationContext whenever you need it.
Hope it helps someone.
Regards
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2010 06:32 AM
hi P3d3r0s0,
i'm also facing same problem?
I can't able to follow ur post,so pls can u provide detail information.
I'm having
1) when we implement the ApplicationContextAware how will you set content for setApplicationContext(app-content) ?
2)where to place the class file (alfresco/server used for webservice)?
3)How to get the applicationcontent in client side.
4)In your post "your.package.and.class.name.in.repository" shoulb in which repository?
do u have sample application if? pls provide it..
thanks in advance.
i'm also facing same problem?
I can't able to follow ur post,so pls can u provide detail information.
I'm having
1) when we implement the ApplicationContextAware how will you set content for setApplicationContext(app-content) ?
2)where to place the class file (alfresco/server used for webservice)?
3)How to get the applicationcontent in client side.
4)In your post "your.package.and.class.name.in.repository" shoulb in which repository?
do u have sample application if? pls provide it..
thanks in advance.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2010 12:21 PM
Hey,
I have a class in repository named AppContext, its in a package named myPacket.
I have only 2 methods inside:
Inside the repository project, in config/alfresco, theres a application-context.xml file. In that file i had the line:
<bean id="appContext" class="myPacket.AppContext"></bean>
in the end, before the </beans>
After having this done, i can access the applicationContext by using the static method AppContext.getApplicationContext();
Im using in another class in the repository like this:
protected static ApplicationContext ctx = AppContext.getApplicationContext();
Hope this helps.
ps: i never use the Set method in appContext. Alfresco/Spring injects/sets the applicationContext for you.
I have a class in repository named AppContext, its in a package named myPacket.
I have only 2 methods inside:
package myPacket;import javax.faces.context.FacesContext;import org.springframework.beans.BeansException;import org.springframework.context.ApplicationContext;import org.springframework.context.ApplicationContextAware;public class AppContext implements ApplicationContextAware{ private static ApplicationContext ctx; @Override public void setApplicationContext(ApplicationContext arg0) throws BeansException { ctx = arg0; } public static ApplicationContext getApplicationContext(){ return ctx; }}
Inside the repository project, in config/alfresco, theres a application-context.xml file. In that file i had the line:
<bean id="appContext" class="myPacket.AppContext"></bean>
in the end, before the </beans>
After having this done, i can access the applicationContext by using the static method AppContext.getApplicationContext();
Im using in another class in the repository like this:
protected static ApplicationContext ctx = AppContext.getApplicationContext();
Hope this helps.
ps: i never use the Set method in appContext. Alfresco/Spring injects/sets the applicationContext for you.
