Announcement Announcement Module
Collapse
No announcement yet.
context:annotation-config and UserService injection into webservice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • context:annotation-config and UserService injection into webservice

    @javax.jws.WebService(endpointInterface = "... Here is my problem.

    In my "Entry Point" I am not getting UserService instantiated by "web container". If I use

    ugly way of loading (Commented out lines) it works fine. Can someone shed some lights on what

    I am doing wrong there.

    My service and impl

    public interface UserService {
    boolean authenticate(final String userName, final String password);
    }

    public class UserServiceImpl implements UserService {
    @javax.annotation.Resource
    private LdapTemplate ldapTemplate;

    public void setLdapTemplate(final LdapTemplate ldapTemplate) {
    this.ldapTemplate = ldapTemplate;
    }
    public UserServiceImpl() {
    }
    public boolean authenticate(String userName, String password) { .... }

    My entry point class for web service.

    @javax.jws.WebService(endpointInterface = "......AuthenticationPortType", targetNamespace = ".....", serviceName = "....", portName = "AuthenticationService", wsdlLocation = "...")
    public class AuthenticationBindingImpl {

    private static Logger log = Logger.getLogger(AuthenticationBindingImpl.class);

    private UserService userService;

    public void setUserService(UserService userService) {
    this.userService = userService;
    }

    public AuthenticateResult authenticate(Authenticate parameters) {

    /** GenericApplicationContext appContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
    appContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource(
    "/WEB-INF/application-context.xml"));
    appContext.refresh();

    userService = (UserService) appContext.getBean("userService"); **/

    AuthenticateResult ar = new AuthenticateResult();
    long start = System.currentTimeMillis();

    log.info("Authenticating : " + parameters.getUsername() + " : From : " + parameters.getSourceIp());

    //Following is NullPointer as userService is null (not instantiated
    boolean result = <b>userService.authenticate</b>(getUserName(parameters
    .getUsername()), parameters.getPassword());

    My config file

    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
    <constructor-arg ref="contextSource" />
    </bean>
    <bean id="userService" class="....UserServiceImpl">
    <property name="ldapTemplate" ref="ldapTemplate" />
    </bean>
    <bean id="authenticationService" class="....AuthenticationBindingImpl">
    <property name="userService" ref="userService" />
    </bean>
Working...
X