Announcement Announcement Module
Collapse
No announcement yet.
GWT 1.5, hibernate4gwt, spring config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • GWT 1.5, hibernate4gwt, spring config

    I'm trying to use GWT 1.5, hibernate4gwt (see sourceforge site ), and spring all together. I'm fairly new to all three, but I'm pretty sure my problem is with my Spring configuration, though I've yet to figure it out. Most things I've taken from tutorials and such, admittedly without fully understanding them.
    My ultimate problem is that my userDao is not getting initialized, but I think it best to give the full context of what's happening (darn - now that I've written it all out, I had hoped that doing so in itself would lead me to a solution, but such is not the case).

    What should happen:
    I have two buttons on a page linked to remote procedure calls.
    The first calls Proj1Service.getMessage(...) which returns some text. The second calls UserService.getUser(...) which (in theory) will return a User object (populated from db with hibernate4gwt) to my Javascript (I believe in JSON).

    What is happening:
    When servlet-mappings are defined in web.xml (currently commented out in code below):
    The first button (for Proj1Service) works fine.
    The second button rpc fails and my own logging shows that my userDao is null. For some reason spring is not initializing it for me.
    When servlet-mappings are commented out in web.xml (as it seemed they should be from this (the software-wonders blog on blogspot dot com slash 2007/02 sl4sh it-is-not-mistery-that-google-web dot html) article, and the dispatcher-servlet is to take care of it):
    Neither button works. Clicking either produces the same result, which is the following output to my spring.log file (a bit text-scrambled due to passing the posting-a-url-preventer in this forum):
    Code:
    DispatcherServlet with name 'dispatcher' received request for [/product /proj1. Proj1 /UserService]
    core. CollectionFactory - Creating [java. util. LinkedHashMap]
    servlet. DispatcherServlet - Bound request context to thread: org. apache. catalina. connector. RequestFacade at 12549c4
    servlet. DispatcherServlet - Testing handler map [org. springframework. web. servlet. handler. BeanNameUrlHandlerMapping at 10df4e2] in 
    DispatcherServlet with name 'dispatcher'
    handler. BeanNameUrlHandlerMapping - Looking up handler for [/ UserService]
    servlet. PageNotFound - No mapping for [/product /proj1. Proj1 /UserService] in DispatcherServlet with name 'dispatcher'
    servlet. DispatcherServlet - Cleared thread-bound request context: org. apache. catalina. connector. RequestFacade at 12549c4
    servlet. DispatcherServlet - Successfully completed request
    support. XmlWebApplicationContext - Publishing event in context [org. springframework. web. context. support. XmlWebApplicationContext at a6cbf7]: ServletRequestHandledEvent: ur l =[/product /proj1. Proj1/ UserService]; clien t=[127. 0. 0. 1]; method=[POST]; servlet=[dispatcher]; session=[null]; user=[null]; time=[0ms]; status=[OK]
    support. XmlWebApplicationContext - Publishing event in context [org. springframework. web. context. support. XmlWebApplicationContext at 75e4fc]: ServletRequestHandledEvent: ur l=[/product/proj1. Proj1/ UserService]; clien t=[127. 0. 0. 1]; method=[POST]; servlet=[dispatcher]; session=[null]; user=[null]; time=[0ms]; status=[OK]
    Any thoughts/helps? If I need to include anything further, please let me know. Oh, and yes, in my UserServiceImpl, I do have a getter & setter for my userDao.


    Included below:
    1. web.xml
    2. dispatcher-servlet.xml
    3. product-dao.xml (partial only)
    4. product-bus.xml (partial only)

    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
            PUBLIC "... stuff ...">
    <web-app xmlns="i can't post links yet"
               xmlns:xsi="so I can't show these"
               xsi:schemaLocation="until i've made 15 posts here"
               version="2.5">
        <display-name>My Product</display-name>
        
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>
        
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:product-database.xml
                classpath:product-dao.xml
                classpath:product-bus.xml
            </param-value>
        </context-param>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet>
            <servlet-name>Proj1Service</servlet-name>
            <servlet-class>com.parks.proj1.server.Proj1ServiceImpl</servlet-class>
        </servlet>
        <servlet>
            <servlet-name>UserService</servlet-name>
            <servlet-class>com.parks.proj1.server.UserServiceImpl</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/proj1.Proj1/*</url-pattern>
        </servlet-mapping>
    
        <!-- commented out at the moment, see notes below -->
        <!-- servlet-mapping>
            <servlet-name>Proj1Service</servlet-name>
            <url-pattern>/proj1.Proj1/Proj1Service</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>UserService</servlet-name>
            <url-pattern>/proj1.Proj1/UserService</url-pattern>
        </servlet-mapping -->
    </web-app>

    dispatcher-servlet.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="more urls I can't show"
           xmlns:xsi="quite silly really"
           xsi:schemaLocation="but I see where they're coming from">
    
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="openSessionInViewInterceptor" />
                </list>
            </property>
            <property name="mappings">
                <props>
                    <prop key="/Proj1Service">p1ServiceController</prop>
                    <prop key="/UserService">userServiceController</prop>
                </props>
            </property>
        </bean>
    
        <bean id="p1ServiceController" class="org.springframework.web.servlet.mvc.ServletForwardingController">
            <property name="servletName" value="Proj1Service" />
        </bean>
    
        <bean id="userServiceController" class="org.springframework.web.servlet.mvc.ServletForwardingController">
            <property name="servletName" value="UserService" />
        </bean>
    
        <bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
            <property name="flushModeName" value="FLUSH_AUTO" />
        </bean>
    </beans>

    product-dao.xml:
    Code:
    ...
        <bean id="hibernateBeanManager"
              class="net.sf.hibernate4gwt.core.HibernateBeanManager">
            <!-- property name="pojoStore" ref="pojoStore" / - - don't think I need this as of h4gwt-1.1 -->
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
    
        <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="location" value="classpath:conf/product-hibernate.properties"/>
        </bean>
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" autowire="byName">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="classpath:product-hibernate.cfg.xml"/>
            <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
            <property name="hibernateProperties" ref="hibernateProperties"/>
        </bean>
    
        <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" autowire="autodetect" />
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" autowire="byName" />
    
    
        <tx:annotation-driven transaction-manager="transactionManager"/>
    
        <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor" autowire="byName" />
        <bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor" autowire="autodetect" />
        <bean id="transactionAttributeSource" class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
    
        <bean id="springApplicationContext" class="com.parks.proj1.lib.util.SpringApplicationContext" autowire="byName"/>
        <bean id="userDao" class="com.parks.proj1.server.dao.impl.UserDaoImpl" autowire="byName"/>
    ...

    product-bus.xml:
    Code:
    ...
       <bean id="userService" class="com.parks.proj1.server.UserServiceImpl">
            <property name="beanManager" ref="hibernateBeanManager"/>
            <property name="userDao" ref="userDao"/>
        </bean>
    ...

  • #2
    Hi I'm not so sure about this.. but you can give it a try

    in your web.xml context-param are passed in multiple lines... try to put all values for contextConfigLocation in single line separated by a comma (,).

    Code:
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:product-database.xml, classpath:product-dao.xml, classpath:product-bus.xml
            </param-value>
    </context-param>

    Comment


    • #3
      1) Why is your UserServiceImpl mapped as both a service and as a servlet? Only the servlet one is going to be used it doesn't know anything about the one in the mapping file.
      2) due to this no injection is taking place.

      In your configuration your Controllers are mapped to a ServletForwardingFilter, you commented out the servlets, which don't get injected, and thus an exception.

      You have some duplication going one, why use @Transactional but still supply a TransactionInterceptor, the same goes for your autoProxyCreator.
      Last edited by Marten Deinum; Jul 18th, 2008, 03:49 AM.

      Comment

      Working...
      X