Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to component import with spring scanner?

Hi everyone,

So I am now working on the posting notifications in confluence tutorial. Which can be found here . I've run into many many issues along the way. Now I am wondering how I would component import with the spring scanner. I've read about the spring scanner stuff but I am still unsure if I am doing it right. You see in the tutorial they say to put this line  in the atlasssian-plugin.xml 

<component-import key="notificationService" interface="com.atlassian.mywork.service.LocalNotificationService"/>

 but when I do that I get an error that states:

atlassian-plugin.xml contains a definition of component-import. This is not allowed when Atlassian-Plugin-Key is set.

 Based off of what I've read I edited my to look like this

package com.example.plugins.tutorial.confluence.notification.resource;

import java.util.concurrent.ExecutionException;

import javax.annotation.Nullable;
import org.springframework.stereotype.Scanned;

import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.UserAccessor;
import com.atlassian.mywork.model.Notification;
import com.atlassian.mywork.model.NotificationBuilder;
import com.atlassian.mywork.service.LocalNotificationService;
import com.atlassian.user.impl.DefaultGroup;

* A resource of creating and listing notifications
@Path ("/")
@Consumes (MediaType.APPLICATION_JSON)
@Produces (MediaType.APPLICATION_JSON)
public class NotificationResource {
private final LocalNotificationService notificationService;
private final UserAccessor userAccessor;
private final PermissionManager permissionManager;

public NotificationResource(final LocalNotificationService notificationService, final UserAccessor userAccessor, final PermissionManager permissionManager) {
this.notificationService = notificationService;
this.userAccessor = userAccessor;
this.permissionManager = permissionManager;
public Response createNotification(@FormParam ("title") String title, @FormParam ("message") String message)
throws Exception {
if (isAdmin()) {
sendNotificationToAllUsers(title, message);
return Response.ok().build();
else {
return Response.status(Response.Status.FORBIDDEN).build();
@Produces (MediaType.APPLICATION_JSON)
public Response findAllNotifications() throws Exception{
if (isAdmin()){
// TODO add code to list past notifications sent by this plugin
return Response.ok().build();
return Response.status(Response.Status.FORBIDDEN).build();
private boolean isAdmin(){
return permissionManager.isConfluenceAdministrator(AuthenticatedUserThreadLocal.getUser());

* Create a single notification and send it to user
* @param user the user who will receive the notification
* @param title the title of the notification
* @param message the body of the notification
* @return the created notification
* @throws InterruptedException
* @throws ExecutionException
private Notification sendNotification(final String user, final String title, final String message) throws InterruptedException, ExecutionException{
Notification notification = notificationService.createOrUpdate(user, new NotificationBuilder()
.application("${project.groupId}.${project.artifactId}") // a unique key that identifies your plugin
.title("Message from your beloved administrator")
.groupingId("com.example.plugins.tutorial.confluence.notification") // a key to aggregate notifications
return notification;

* Iterate on all users of the "confluence-users" group and send a notification to each of them
* @param title the title of the notification to sen
* @param message the body of the notification to send
* @throws ExecutionException
* @throws InterruptedException
private void sendNotificationToAllUsers(final String title, final String message)
throws ExecutionException, InterruptedException {
Pager<String> memberNames = userAccessor.getMemberNames(new DefaultGroup(UserAccessor.GROUP_CONFLUENCE_USERS));
for (String memberName : memberNames) {
sendNotification(memberName, title, message);


 Any help would be greatly appreciated. Thank you for your time. 

1 answer

@Diana Bianco have you solved it? I am in the same situation.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Bitbucket Smart Commits vs. Genius Commits - What's the difference?

If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...

114 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you