How do I get this spring scanner to work? :(

Hi everyone,

So I am working on the writing an admin space screen tutorial and I’m having trouble with the servlet part. I’ve updated my pom.xml so that I can use the spring scanner 2.1.8. However, in the tutorial they use the outdated tags. I am trying to replace them with the @ComponentImport however it is not working.

package com.atlassian.examples.spring;

import com.atlassian.confluence.spaces.Space;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.confluence.user.ConfluenceUser;
import com.atlassian.confluence.user.UserAccessor;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.auth.LoginUriProvider;
import com.atlassian.sal.api.user.UserKey;
import com.atlassian.sal.api.user.UserManager;
import com.atlassian.templaterenderer.TemplateRenderer;

import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static java.util.Objects.requireNonNull;

public class ViewLinkServlet extends HttpServlet {
    private static final String SPACE_ID_KEY = "spaceId";
    private final UserManager userManager;
    private final UserAccessor userAccessor;
    private final LoginUriProvider loginUriProvider;
    private final SpaceManager spaceManager;
    private final TemplateRenderer templateRenderer;

    public ViewLinkServlet( UserManager userManager, UserAccessor userAccessor, LoginUriProvider loginUriProvider,
                            SpaceManager spaceManager, TemplateRenderer templateRenderer) {
        this.userManager = requireNonNull(userManager);
        this.userAccessor = requireNonNull(userAccessor);
        this.loginUriProvider = requireNonNull(loginUriProvider);
        this.spaceManager = requireNonNull(spaceManager);
        this.templateRenderer = requireNonNull(templateRenderer);

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Find current user
        UserKey userKey = userManager.getRemoteUserKey(request);
        ConfluenceUser user = userAccessor.getExistingUserByKey(userKey);
        if (userKey == null || user == null) {
            redirectToLogin(request, response);

        // Find space in the request
        Space space = null;
        String spaceIdString = request.getParameter(SPACE_ID_KEY);
        if (spaceIdString != null) {
            try {
                long spaceId = Long.parseLong(spaceIdString);
                space = spaceManager.getSpace(spaceId);
            } catch (NumberFormatException nfe) {
                // log a warning if needed

        if (space == null) {

                ImmutableMap.of("spaceId", space.getId()),


    private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {

    private URI getUri(HttpServletRequest request) {
        StringBuffer builder = request.getRequestURL();
        if (request.getQueryString() != null) {
        return URI.create(builder.toString());

What am I doing wrong?

Just starting to find my way around working with the spring scanner atm too, so I might not be of much help here, but did you read through the readme here: ?

In particular, did you add the spring.xml here src/main/resources/META-INF/spring/? Your post suggests you only adjusted the pom.xml, while the documentation for the spring scanner suggests this is only part of the necessary work to get the scanner setup correctly for a project.

you need to use @Component instead of @Named , you can poke around some of the configurations in here

Your code is perfectly fine. As Stefan indicated you also have to adjust the plugin-context. Our looks as follows: