As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
final ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml"); final Repository repository = (Repository) context.getBean("JCR.Repository");
If you are using a "Java Backed WebScript" then you don't need it, use spring injection instead.Its in the Repository Project.
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.alfresco.service.ServiceRegistry; public class TestWebScript extends AbstractWebScript implements ApplicationContextAware { private ServiceRegistry serviceRegistry; private ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext arg0) throws BeansException { this.applicationContext = applicationContext; } public void execute(WebScriptRequest req, WebScriptResponse res){ this.serviceRegistry=(ServiceRegistry)applicationContext.getBean("serviceRegistry"); // serviceRegistry.getAnyServices and use them } }
<bean id="webscript.org.alfresco.components.package.testwebscript.get" class="package.TestWebScript " parent="webscript"> <property name="serviceRegistry" ref="ServiceRegistry" /> </bean>
import org.springframework.extensions.surf.RequestContext; import org.springframework.extensions.surf.support.ThreadLocalRequestContext; import org.springframework.extensions.webscripts.AbstractWebScript; import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; import org.springframework.extensions.webscripts.connector.User; public class DemoAction extends AbstractWebScript { @Override public void execute(WebScriptRequest request, WebScriptResponse response) { RequestContext context = ThreadLocalRequestContext.getRequestContext(); User user = context.getUser(); } }