0

in a gwt web application i use spring.

if i use in my applicationContext.xml file

<context:component-scan base-package="com.test.**"/> 

my bean is not found, i need to manually declare it in the applicationContext file.

my web.xml file

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
     <servlet-name>gwtRequest</servlet-name>
     <servlet-class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</servlet-class>
</servlet>

<servlet-mapping>
     <servlet-name>gwtRequest</servlet-name>
     <url-pattern>/gwtRequest</url-pattern>
</servlet-mapping>

<welcome-file-list>
     <welcome-file>welcomeGWT.html</welcome-file>
</welcome-file-list>

Is there any reason why component scan fail?

Locator class

public class AccountLocator extends Locator<Account, Long> {

    @Autowired
    private AccountDAO accountDAO;
    ...
}

Spring service locator

public class SpringServiceLocator implements ServiceLocator {

    @Override
    public Object getInstance(Class<?> clazz) {
        HttpServletRequest request = RequestFactoryServlet.getThreadLocalRequest();
        ServletContext servletContext = request.getSession().getServletContext();
        ApplicationContext context =       WebApplicationContextUtils.getWebApplicationContext(servletContext);
    return context.getBean(clazz);
}

}

Server layer

@Service
public class AccountServiceImpl implements AccountService{
    @Autowired
    private AccountDAO accountDAO;
...
}

Dao layer

@Repository
public class AccountDAOImpl implements AccountDAO{
...
}
4
  • 1
    Could you please post your bean source code. I think you have not specified @Component or (@Service,...) annotation there Aug 24, 2012 at 15:26
  • @Autowired private AccountDAO accountDAO; in the AccountLocator will not work. The locator instance is created by GWT so injection doesn't work. Instead you can use the same approach as in the ServiceLocator class.
    – StefanR
    Aug 29, 2012 at 11:34
  • ok i understand gwt don't do the injection but i don't undersand how to use same approach then ServiceLocator... i can't add it to AccountLocator
    – redfox26
    Sep 13, 2012 at 19:06
  • You could copy (or re-use) the getInstance() method from the SpringServiceLocator in the AccountLocator to get an instance of your AccountDao.
    – StefanR
    Oct 18, 2012 at 19:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.