Re: Spring and gwt (request factory)

307 views
Skip to first unread message

Alfredo Quiroga-Villamil

unread,
Aug 25, 2012, 9:18:15 AM8/25/12
to google-we...@googlegroups.com
In addition to declaring the base package where Spring will start to
search for your "Beans", you have to also annotate the class with
@Component.

Best regards,

Alfredo

On Thu, Aug 23, 2012 at 5:02 PM, pierre leagault
<pierrele...@gmail.com> wrote:
> hi
>
> i use spring and gwt (request factory).
>
> in my applicationContext, i use context component-scan but my bean is not retrieved.
>
> i need to declare it manually.
>
> why component scan don't work?
>
>
> my web.xml
>
> <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>requestFactoryServlet</servlet-name>
> <servlet-class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</servlet-class>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>requestFactoryServlet</servlet-name>
> <url-pattern>/gwtRequest</url-pattern>
> </servlet-mapping>
>
>
> <welcome-file-list>
> <welcome-file>welcomeGWT.html</welcome-file>
> </welcome-file-list>
>
>
> thanks
>
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/4QrWjBivh5YJ.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>



--
Alfredo Quiroga-Villamil

AOL/Yahoo/Gmail/MSN IM: lawwton

pierre leagault

unread,
Aug 25, 2012, 10:35:48 AM8/25/12
to google-we...@googlegroups.com
my service class is annoted with service and my dao with repository

Alfredo Quiroga-Villamil

unread,
Aug 25, 2012, 2:24:42 PM8/25/12
to google-we...@googlegroups.com
This might not directly answer your question but it'll hopefully help.
You will find all the moving pieces you need there. In my DAO, I am
injecting via @Autowired some beans (not shown in the example).

Proxy:
===============================================
@ProxyFor(value = Card.class, locator = CardLocator.class)
public interface CardProxy extends EntityProxy {
.....
===============================================

Entity:
===============================================
@Table(name = "cards")
@Entity
public class Card {

public class CardLocator extends Locator<Card, Integer>{

@Override
public Card create(Class<? extends Card> clazz) {
return new Card();
}

@Override
public Card find(Class<? extends Card> clazz, Integer id) {
return ((CardDAO) BeanContextUtil.getBean(CardDAO.class)).find(id);
}
.....
===============================================

RequestContext:
===============================================
@Service(value = CardDAO.class, locator = CardServiceLocator.class)
public interface CardRequestContext extends RequestContext {
....
===============================================

DAO:
===============================================
@Component
public class CardDAO {
....
===============================================

Service Locator:
===============================================
public class CardServiceLocator implements ServiceLocator {

@Override
public Object getInstance(Class<?> clazz) {
return BeanContextUtil.getBean(CardDAO.class);
}

}
===============================================

Bean Util:
===============================================
public class BeanContextUtil {

public BeanContextUtil() {

}

public static Object getBean(Class<?> clazz) {
HttpServletRequest request =
RequestFactoryServlet.getThreadLocalRequest();
ServletContext servletCtx = request.getSession().getServletContext();
ApplicationContext springCtx =
WebApplicationContextUtils.getWebApplicationContext(servletCtx);
return springCtx.getBean(clazz);
}

}
===============================================

Best regards,

Alfredo
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/xLI56yX5k3MJ.

pierre leagault

unread,
Aug 25, 2012, 4:05:40 PM8/25/12
to google-we...@googlegroups.com
i have something similar but more generic.

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);
    }
}

@ProxyFor(value=Account.class, locator = AccountLocator.class)
public interface AccountProxy extends EntityProxy{
....
}

public class AccountLocator extends Locator<Account, Long> {

    @Autowired
    private AccountDAO accountDAO;

    @Override
    public Account create(Class<? extends Account> clazz) {
        return new Account();

    }

    @Override
    public Account find(Class<? extends Account> clazz, Long id) {
    ...
    }
    ...
}

@Service(locator = SpringServiceLocator.class, value =AccountService.class)
public interface AccountRequest extends RequestContext {
 ...
Reply all
Reply to author
Forward
0 new messages