Configuring Spring
You can plug your spring configs in just about any where as long as you follow the naming conventions *-context.xml and put the file in the correct directory so your amp is correctly over-layed when applied to the alfresco WAR.
I put mine in a file called custom-web-context.xml. Then I put that file into my amps config/alfresco/extension/ directory.
The spring bean configs go as such:
<!-- This bean config creates a singleton instance of our version of alfresco's service registry-->
<bean id="MyCoServiceRegistry" class="org.myco.repo.service.MyCoServiceDescriptorRegistry" parent="ServiceRegistry"></bean>
That is pretty much it as far as the spring config necessary to extend the service registry. Soon I will show you how to extend the Service registry class to make it work with this config. Before that I wanted to mention that I used a DAO pattern along with this service registry extension to implement my JDBC service.
JDBCService Config
<!-- This bean config createers a singleton instance of SimpleJdbcTemplate a very handy spring class -->
<bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<constructor-arg ref="defaultDataSource" />
</bean>
<bean id="MyCoJDBCService" class="org.myco.repo.service.MyCoJDBCServiceImpl">
<property name="workFlowNameMappingDAO" ref="workFlowNameMappingDAO" />
</bean>
<bean id="workFlowNameMappingDAO" class="org.myco.repo.dao.WorkFlowNameMappingDAO">
<property name="simpleJdbcTemplate" ref="simpleJdbcTemplate" />
</bean>
Now you can simply plug your new service registry into any bean and have all the existing alfresco services available as well as your new service.
Note: One thing to consider using this method, it kind of undermines spring IoC but it is super convenient.
Extending the service registry class
public class MyCoServiceDescriptorRegistry extends org.alfresco.repo.service.ServiceDescriptorRegistry
{
static final QName MYCO_JDBC_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "MyCoJDBCService");
public MyCoJDBCService getMyCoJDBCService()
{
return (MyCoJDBCService)getService(MYCO_JDBC_SERVICE);
}
}
That will just about do it. The overhead should be fairly low because our new class is a singleton. As you know because we are extending Alfresco's ServiceRegistry class we get all those methods as well and by telling spring that Alfresco's ServiceRegistry config is our parent it knows to inject it with all the necessary dependencies.
Enjoy :)