Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,416
Community Members
 
Community Events
165
Community Groups

No qualifying bean of type 'com.atlassian.confluence.user.UserAccessor' available error

Hi, I am trying to import the UserAccessor in my servlet class. However, whenever I use the servlet module, this error pops up:

com.atlassian.util.concurrent.LazyReference$InitializationException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘dso.intern.plugin.BulkUserCreatorToolServlet’: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.atlassian.confluence.user.UserAccessor’ available: expected
at least 1 bean which qualifies as autowire candidate.

Here’s my code:

@Named("BulkUserCreatorToolServlet") 
public class BulkUserCreatorToolServlet extends HttpServlet{
private final UserAccessor userAccessor;
public BulkUserCreatorToolServlet(UserAccessor userAccessor){
this.userAccessor = userAccessor;
}

@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure a repository (to ensure a secure temp location is used)
ServletContext servletContext = this.getServletConfig().getServletContext();
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
// Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory);

try{
//Parse the request to get file items List<FileItem> fileItems = upload.parseRequest(request);
// Process the uploaded items Iterator<FileItem> iter = fileItems.iterator();
String contentType = null; while(iter.hasNext()){
FileItem item = iter.next();
if(!item.isFormField()){
String content = item.getString();
StringReader sReader = new StringReader(content);
Iterable<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(sReader);
(CSVRecord record : records){
String username = record.get("Username"); //UTF-8 BOM
String fullname = record.get("Fullname");
String email = record.get("Email");
String password = record.get("Password");
String groupsToBeAddedInto = record.get("GroupsToBeAddedInto");
DefaultUser defaultUser = new DefaultUser(username, fullname, email);
ConfluenceUser newUser = userAccessor.createUser(defaultUser, Credential.unencrypted(password));
userAccessor.addMembership(UserAccessor.GROUP_CONFLUENCE_USERS, username); } } }

response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter(); out.println("<!DOCTYPE html>");
out.println("<html><head>"); out.println("<meta name=\"decorator\" content=\"atl.admin\" />");
out.println("<title>Response Page</title></head></html>"); }

catch(FileUploadException e){ e.printStackTrace(); }
catch(Exception e){ e.printStackTrace(); } } }

 What did I do wrong? Thank you

1 answer

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

186 views 1 3
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