cancel
Showing results for 
Search instead for 
Did you mean: 

override

litllel
Champ in-the-making
Champ in-the-making
Hi guys, what is the structure to create an AMP and override existing Java code in jar.
Thks
1 ACCEPTED ANSWER

nikhilesh_s1vak
Confirmed Champ
Confirmed Champ

Hi,

After so many days of investigation and repeated failures i found a solution for the above issue which i thought i could end up finding any answer.

I have kept these custom context files under the "classpath:alfresco/extension/custom-web-context.xml" and the changes are picked up after the restart and my custom bean has overridden the OOTB beans.

I have found this information in the web-application-context.xml file under the path <root>\tomcat\webapps\alfresco\WEB-INF

<!--

        To give final control over the tuning of the custom environment, the custom-web-context.xml file is processed

        last (note: custom-web-context.xml isn't part of the source tree itself).

         -->

    <import resource="classpath*:alfresco/extension/custom-web-context.xml" />

Hope this helps someone who is looking for an answer.

View answer in original post

9 REPLIES 9

steven_okennedy
Star Contributor
Star Contributor
Use the Alfresco SDK, it's the easiest way to create an amp. It also has built-in examples of how to do most types of customisation as well that you can use as a base. http://docs.alfresco.com/5.1/concepts/alfresco-sdk-intro.html

ok, thanks and can I override a spring bean definition who is inside a jar. If yes, how can I do it?

Spring configuration is based on what boils down to basically "last loaded wins!".  Alfresco's extension points are designed to have their spring context files loaded <em>after</em> the standard out of the box ones, which means that to override a Spring bean in an extension project, all you need to do is put a bean in your module-context.xml file (or any files that are included from there) and it will override any existing bean with the same name.

It doesn't really matter whether the original bean definition is included in the WEB-INF/classes directory of the war, or is bundled in one of the jar files.  The only thing you would need to worry about is if you are using multiple modules (AMPs) that attempt to override the same bean.  In this case the one that gets loaded last will take effect.

Regards

Steven

Hi Steven,

I tried to override the Content retrieval webscript in alfresco 5.1 EE. I have copied the web-scripts-application-context.xml to the module's context folder and changed the class attribute to my custom class, keeping the bean id as it is. Now when i check in the repository webscript index page, the content.get webscript still points to the OOTB  service instead of my custom class. But the same was working in v4.1.9. Not sure if i am missing something here. Any help would be appreciated.

Regards,
Nikhilesh

steven_okennedy
Star Contributor
Star Contributor
Hi Nikhilesh,

By default your amp module will load one context file automatically, the module-context.xml file - any other context files you include won't be picked by Spring unless you tell it to.  So if you want to include a file called web-scripts-application-context.xml in your module's context folder you'll need to add an import in module-context.xml that looks something like

<import resource="classpath:alfresco/module/${project.artifactId}/context/web-scripts-application-context.xml" />


Another option is to copy just the bean that you're overriding into one of the existing context files that are already loaded, either module-context.xml itself or one of the other files that are imported from there by default.

Regards

Steven

Hi Steven,

Yes, I have imported the web-scripts-application-context.xml in the module-context file and copied the bean to the context file and to module-context file either. But both are not working in my case. As i mentioned earlier comment, the same was working in 4.1.9 but it is not an AMP deployment. I wonder this process might have changed in 5.x or they removed the support for overriding the OOTB beans.

Thanks,
Nikhilesh

Hi Nikhilesh,

No they have not removed the ability to override beans, it's still provided as basic Spring functionality.  Are you using any other amps with your project that may also be overriding this bean?

It might be simplest if you post your module-context.xml & supporting files

Regards

Steven

Hi Steven,

Thanks for quick reply. Yes i am using another default amp "alfresco-share-services" with the project. But the other amp is not overriding anything related to content.get service except a bean in this amp is extending content.get but not overriding. Please find the attached the module-context file. The same bean declarations are removed from web-scripts-application-context file and added to module-context file.

Thanks,
Nikhilesh

nikhilesh_s1vak
Confirmed Champ
Confirmed Champ

Hi,

After so many days of investigation and repeated failures i found a solution for the above issue which i thought i could end up finding any answer.

I have kept these custom context files under the "classpath:alfresco/extension/custom-web-context.xml" and the changes are picked up after the restart and my custom bean has overridden the OOTB beans.

I have found this information in the web-application-context.xml file under the path <root>\tomcat\webapps\alfresco\WEB-INF

<!--

        To give final control over the tuning of the custom environment, the custom-web-context.xml file is processed

        last (note: custom-web-context.xml isn't part of the source tree itself).

         -->

    <import resource="classpath*:alfresco/extension/custom-web-context.xml" />

Hope this helps someone who is looking for an answer.