Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

AEM - Java servlet can't register on fresh 6.4 install


Level 1

Hey Everyone,

I've been dealing with a really tricky issue on a fresh AEM 6.4 install. One of my servlets cannot start. It can register fine and shows up okay however, it always throws a 404 at the path its registered at. I deleted and re-installed my AEM and the issue still persists. The error is very cryptic and there isnt much on the internet about it.

Has anyone every seen? "Service factory returned null"

10.05.2018 14:45:04.358 *ERROR* [FelixDispatchQueue] FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null. (Component: com.amsurg.core.servlets.RSSXMLServlet (3142)))

org.osgi.framework.ServiceException: Service factory returned null. (Component: com.amsurg.core.servlets.RSSXMLServlet (3142))

It's nothing with my code and I have several other servlets that register just fine. This particular one was working earlier then just stopped. Anyone have any troubleshooting ideas? I've tried re-building, restarting AEM, and checking the servlet sling checker but nothing seems to be able to find it.

It registers okay and shows up in the bundle as

Service ID 6903Types: javax.servlet.Servlet
Service PID: com.amsurg.core.servlets.RSSXMLServlet
Component Name: com.amsurg.core.servlets.RSSXMLServlet
Component ID: 3142
Vendor: Adobe

But underneath it there is no part that looks like this


Description: ServletResourceProvider for Servlets at [/libs/amsurg/structure/page/GET.servlet, /libs/amsurg/structure/page/HEAD.servlet]

Anyone have any troubleshooting ideas? This is how it is registered - @SlingServlet(paths = "/bin/feed", methods = "GET", metatype = true)



4 Replies


Community Advisor

I tried to create servlet in AEM6.4, for me its working fine.

below is sample servlet code which I've created


  property= {

  Constants.SERVICE_DESCRIPTION + "=TitleSlindServlet Demo Servlet",


            "sling.servlet.methods=" + HttpConstants.METHOD_GET,

            "sling.servlet.extensions=" + "html"


public class TitleSlingServlet extends SlingSafeMethodsServlet{

  private static final long serialVersionUID = 1L;


    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

  response.setHeader("Content-Type", "text/html");

    response.getWriter().print("<h1>Sling Servlet injected this title");








Can you please share your code? and full error.log?

Team would require Source code to check this up. Maybe you using service which is no longer available in AEM.



Level 10

For more current versions of AEM - you should be DS annotations ( org.osgi.service.component.annotations.Component) to create Servlets.


* Servlet that writes some sample content into the response. It is mounted for

* all resources of a specific Sling resource type. The

* {@link SlingSafeMethodsServlet} shall be used for HTTP methods that are

* idempotent. For write operations use the {@link SlingAllMethodsServlet}.




                Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

                "sling.servlet.methods=" + HttpConstants.METHOD_POST,

                "sling.servlet.paths="+ "/bin/myDataSourcePoolServlet"


public class SimpleServlet extends SlingAllMethodsServlet {

See this article for an example -- Scott's Digital Community: Creating a Mail List Component for the Experience Manager Toy Store Site


Community Advisor

Also make sure you are not using JcrResourceResolverFactory or loginadministrator to get resourceResolver object and use system user to get the resolver as shown below

Map<String, Object> param = new HashMap<String, Object>();

param.put(ResourceResolverFactory.SUBSERVICE, "user");

ResourceResolver resolver = null;

try {

     resolver = resolverFactory.getServiceResourceResolver(param);

     session = resolver.adaptTo(Session.class);


Hope it helps!