Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:41:46+00:00 2026-05-28T01:41:46+00:00

I cannot seem to inject a simple bean into my @WebService . With Spring

  • 0

I cannot seem to inject a simple bean into my @WebService. With Spring on the classpath and javax.inject dependencies defined, I created a simple JAX-WS webservice with some underlying interface-driven DAOs etc:

@Named
@WebService(name = "NoteStorage", serviceName = "NoteStorageWS")
public class NoteStorageWS implements NoteStore {

    private static final Log l = LogFactory.getLog(NoteStorageWS.class);

    @Named("NoteDAO")
    @Inject
    private NoteDAO noteDAO;

    public NoteStorageWS() {
        super();
    }

    @Override
    @WebMethod
    public StorageState takeNote(String note) {
        try {
            l.info(format("Service received message: '%s'", note));

            Note n = new Note();
            n.setContent(note);
            noteDAO.store(n);

        } catch (Exception e) {
            l.error(e);
            return StorageState.FAILURE;
        }
        return StorageState.SUCCESS;
    }

    @WebMethod(exclude = true)
    public void setNoteDAO(NoteDAO noteDAO) {
        this.noteDAO = noteDAO;
    }
}

NoteDAOhas just implementation: FlatFileNoteDAO which is defined as follows:

@Named("NoteDAO")
public class FlatFileNoteDAO implements NoteDAO {

    private static final Log l = LogFactory.getLog(FlatFileNoteDAO.class);

    @Override
    public void store(Note n) {
        if (n == null) {
            throw new IllegalArgumentException("Note was null");
        }

        try {
            l.info(format("Storing note '%s'", n));
            FileWriter fileWriter = new FileWriter(new File("Note"));
            fileWriter.write(format("%s\n", n.getContent()));
            fileWriter.close();
        } catch (IOException e) {
            throw new DataAccessException(e);
        }

    }

}

My web.xml says:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/context.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <resource-env-ref>
        <description>Object factory for the CDI Bean Manager</description>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>
</web-app>

I deploy the application to Glassfish by pointing it to the target/note-ws/ directory and execute the simple takeNote method via the ?Tester page.

Upon submission of the tester form I get a NullPointerException at the line noteDAO.store(n);, presumably because noteDAO wasn’t injected.

I can confirm that Spring has been invoked by the logs from glassfish on context initialisation (the Java EE context):

[#|2011-12-04T16:57:24.970+0000|INFO|glassfish3.1.1|org.springframework.context.annotation.ClassPathBeanDefinitionScanner|_ThreadID=256;_ThreadName=Thread-2;|JSR-330 'javax.inject.Named' annotation found and supported for component scanning|#]

    [#|2011-12-04T16:57:25.653+0000|INFO|glassfish3.1.1|org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor|_ThreadID=256;_ThreadName=Thread-2;|JSR-330 'javax.inject.Inject' annotation found and supported for autowiring|#]

    [#|2011-12-04T16:57:25.757+0000|INFO|glassfish3.1.1|org.springframework.beans.factory.support.DefaultListableBeanFactory|_ThreadID=256;_ThreadName=Thread-2;|Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@9e39146: defining beans [noteStorageWS,NoteDAO,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy|#]

which says my beans are defined: noteStorageWS, NoteDAO and so-on.

Any ideas?

Edit
to clarify, I’m using Spring to provide JSR 330 — dependency injection — functionality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:41:47+00:00Added an answer on May 28, 2026 at 1:41 am

    I never got this solved, so I ended up removing the DI-features as the codebase was small and relied on manual dependency resolution – plain old new IFaceImpl(); for now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to inject Spring beans into an EJB using @Interceptors(SpringBeanAutowiringInterceptor.class) but I cannot
I have a relatively simple question that I cannot seem to find the answer
I cannot seem to be able to inject a Seam component inside the @Create
I cannot seem to make this simple code work: <script type=text/javascript> $(document).ready(function(){ $.getJSON('http://maps.google.com/maps/api/geocode/json?address=cebu&sensor=false&region=ph', function(results)
For some reasons I cannot seem to populate a datagrid I get the following
I have a simple problem that I cannot seem to find a solution to.
I cannot seem to debug my JavaScript code with Firebug. The play button is
I cannot seem to access the context object using a loop context is set:
I cannot seem to compile mod_dontdothat on Windows. Has anybody managed to achieve this?
I cannot seem to figure out I am getting the following error in IE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.