Saturday, February 28, 2015

How to Configure/Integrate Spring Framework with ATG

Introduction:


Spring is a framework (open source). More important thing here is ATG accepts spring based application which can be integrate along with ATG modules. Spring framework providing the way to establish its mechanism to ATG with the help of nucleus based approach. Spring is based on JavaBeans as like as Nucleus.


Steps to start with:



1. Create a spring framework entry in web.xml which is available in our ATG projects, 
<servlet>
   <servlet-name>spring</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
   <servlet-name>spring</servlet-name>
   <url-pattern>/spring/*</url-pattern>
</servlet-mapping>

a) DispatcherServlet act as controller and it is a bridge between ATG and Spring components


2. Make sure our pageFilter has a entry for spring under <filter-mapping>




<filter-mapping>
    <filter-name>PageFilter</filter-name>
    <url-pattern>/spring/*</url-pattern>
</filter-mapping>

a) DAF pipeline will take care of rest of the process.
 










3. We should use Two OOTB ATG Classes for this spring integration






a) NucleusResolverUtil:




It contains a single static resolveName method. which attempts to resolve the specified Nucleus path. Since Spring is unaware of Nucleus component scope. 
It will check resolve name on current request, if it is fails then in next attempt it will resolve the name in the global Nucleus scope.

eg:
To make a Nucleus component available in Spring, you declare it in your Spring configuration XML file. For example, to resolve the current user profile as a Spring component:
<bean name="/Profile" class="atg.nucleus.spring.NucleusResolverUtil"
    factory-method="resolveName" singleton="false">
  <constructor-arg value="/atg/userprofiling/Profile"/>
</bean>
a) singleton="false" : Profile is a session based component. only global scope component will be specified as singleton="true", request and session component should be specified as  
singleton="false"


b) NucleusPublisher:



The NucleusPublisher class publishing a Spring configuration to nucleus path.

<bean name="/NucleusPublisher" class="atg.nucleus.spring.NucleusPublisher"
    singleton="true">
  <property name="nucleusPath">
    <value>/atg/spring/MyspringBeanClass</value>
  </property>
</bean>







4. We have to add springtonucleus.jar


Path: <ATGDir>/DAF/spring/lib/springtonucleus.jar. 

a) NucleusPublisher requires access to the Spring classes, so the springtonucleus.jar must be added to the WEB-INF/lib




5. Now you can check your application






Popular Posts