내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Empty Activate function with @Activate annotation

Avatar

Level 2

In a project I am working on there are multiple servlets, services with an activate function with @activate annotation where the function has no body, said activate function is taking a configuration as parameter. The configuration has a single field. I am attaching code snippet for one such case below for reference. 
What is the reason behind these empty activate functions, as they are not passing any value from configuration. furthermore what impact might removing such activate function can cause.
service.PNG
config.PNG

comp.png

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

Hi @shubham_naik to me it looks like a dead code. In my opinion having empty activate method does not bring any benefit. I think that removing such an empty activate method will not affect component/service functionality. In other words it should be safe to remove those methods. There is a nice documentation page that explains OSGi component lifecycle including activate, modify, deactivate annotation/methods usage - maybe this could be useful for you.

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-servi...

 

원본 게시물의 솔루션 보기

4 답변 개

Avatar

정확한 답변 작성자:
Community Advisor

Hi @shubham_naik to me it looks like a dead code. In my opinion having empty activate method does not bring any benefit. I think that removing such an empty activate method will not affect component/service functionality. In other words it should be safe to remove those methods. There is a nice documentation page that explains OSGi component lifecycle including activate, modify, deactivate annotation/methods usage - maybe this could be useful for you.

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-servi...

 

Avatar

Level 2

Thanks @lukasz-m , even I thought the same, but it always helps to get a confirmation before decommissioning any code, thanks a lot for the help.👍

Avatar

Employee Advisor

Yes I agree with @lukasz-m here, if you want to understand OCD with @activate ,modify and deactivate annotations , please refer this : https://aem4beginner.blogspot.com/ocd-issue-with-activate-annotation

 

Avatar

Level 2

Thanks a lot for the confirmation and resources @DEBAL_DAS