Announcement Announcement Module
Collapse
No announcement yet.
Spring WS and Hibernate SessionFactory not set Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring WS and Hibernate SessionFactory not set

    Hi all,

    Having a problem with the sessionFactory not been set on a DaoImpl when accessed via WebServices.

    Works fine via the Browser within the same Application.

    1) Via Spring MVC
    PersonController -> PersonDao -> PersonDaoImpl -> SessionFactory (Works fine)

    2) Via Spring WS (Using JiBX Marshalling/UnMarshalling)
    PersonEndpoint -> PersonService -> PersonServiceImpl -> PersonDao -> PersonDaoImpl -> SessionFactory (NullPointerException)

    Versions:
    Spring 3.0.5.RELEASE
    Spring WS 2.0.0.RELEASE

    The PersonDaoImpl is wired as follows:

    <bean id="personDao" class="com.xxx.yyy.business.dao.impl.PersonDaoImpl ">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    Contents of spring-ws-servlet.xml below:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:sws="http://www.springframework.org/schema/web-services"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    						   http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
    						   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <context:annotation-config/>
    	<context:component-scan base-package="com.xxx.yyy"/>
        <sws:annotation-driven/>
    
        <sws:dynamic-wsdl id="Person" 
    					  portTypeName="PersonResource" 
    					  locationUri="/PersonService/"
                          targetNamespace="http://www.xxx.com/yyy/definitions">
            <sws:xsd location="/WEB-INF/xsd/Person.xsd"/>
        </sws:dynamic-wsdl>
    	
    	<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
    
    	<bean id="personResponseMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
    		<property name="bindingName" value="JiBXBindingPerson"/>
    		<property name="targetClass" value="com.xxx.yyy.resources.model.Person"/>
    	</bean>
    	
    	<bean id="personRequestUnmarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
    		<property name="bindingName" value="JiBXBindingPerson"/>
    		<property name="targetClass" value="com.xxx.yyy.ws.pojo.PersonRequest"/>
    	</bean>
    	
        <bean class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
            <constructor-arg ref="personResponseMarshaller"/>
            <constructor-arg ref="personRequestUnmarshaller"/>
        </bean>		
    </beans>
    Contents of spring-application-servlet.xml below:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:context="http://www.springframework.org/schema/context"
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    						   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
            <property name="interceptors" ref="localeChangeInterceptor"/>
        </bean>
    	
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    
        <context:annotation-config/>
        <context:component-scan base-package="com.xxx.yyy.web.servlet.mvc.controllers" />
        
        <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
            <property name="definitions">
                <list>
                    <value>/WEB-INF/tiles-defs/templates.xml</value>
                </list>
            </property>
        </bean>
    
        <bean id="dynamicTilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass" value="com.xxx.yyy.web.servlet.view.tiles2.DynamicTilesView" />
    		<property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    	
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basenames">
                <value>messages</value>
            </property>
        </bean>
        
        <!-- Declare the Interceptor -->
        <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="locale"/>
        </bean>
        
        <!-- Declare the Resolver -->
        <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>	
    </beans>
    Contents of web.xml below:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="CareRecord_1.2" version="2.4" 
             xmlns="http://java.sun.com/xml/ns/j2ee" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
                                 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
        <display-name>CareRecord</display-name>
        
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/context.xml</param-value>
        </context-param>
    
    	<context-param>
    		<param-name>defaultHtmlEscape</param-name>
    		<param-value>true</param-value>
    	</context-param>
    
        <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
    	
        <filter>
            <filter-name>encoding-filter</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>encoding-filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
        	
        <servlet>
            <servlet-name>spring-application</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>spring-application</servlet-name>
            <url-pattern>*.html</url-pattern>
        </servlet-mapping>
    
        <servlet>
            <servlet-name>spring-report</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>spring-report</servlet-name>
            <url-pattern>*.rpt</url-pattern>
        </servlet-mapping>
        
    	<servlet>
    		<servlet-name>spring-ws</servlet-name>
    		<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    		<init-param>
    		  <param-name>transformWsdlLocations</param-name>
    		  <param-value>true</param-value>
    		</init-param>
    	</servlet>
    	
    	<servlet-mapping>
    		<servlet-name>spring-ws</servlet-name>
    		<url-pattern>/PersonService/*</url-pattern>
    	</servlet-mapping>
    
    	<welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    	
    	<resource-ref>
    		<res-ref-name>jdbc/CareRecordDS</res-ref-name>  
    		<res-type>javax.sql.DataSource</res-type>  
    		<res-auth>Container</res-auth>
    	</resource-ref> 
    </web-app>
    Any help or pointers would be appreciated.

    Regards,
    Conor

  • #2
    Hi all,

    I managed to solve the problem.

    I changed the SessionFactory to be @Autowired by annotations instead of the traditional Spring method. The Spring WS wired it up correctly.

    Regards,
    Conor

    Comment

    Working...
    X