Hi,
I've been trying to get a web service up and running which uses Tomcat + Axis + Spring + Hibernate. The web service implementation extends ServletEndpointSupport, but I can't seem to get access to the application context. As far as I can see the onInit method is never called:
However, I have been able to get it to work by not extending ServletEndpointSupport and using this code in the business method of the web service implementation to get the application context instead:Code:public class RepositorySoapBindingImpl extends ServletEndpointSupport implements Repository { private DataSetDAO dao; protected void onInit() { dao = (DataSetDAO)getWebApplicationContext().getBean("dataSetDAO"); } public String getDataSetComplete(long dataSetId) throws RemoteException, RepositoryServiceFault { IDataSet ds = dao.getDataSetComplete(dataSetId); //etc } }
This seems like a bit of a hack though, and I'd really like to use ServletEndpointSupport - if anyone can tell me how to get it to work!!Code:HttpServlet servlet = (HttpServlet) MessageContext.getCurrentContext().getProperty( HTTPConstants.MC_HTTP_SERVLET); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext());
cheers, Rob
web.xml:
context.xml:Code:<?xml version="1.0" encoding="ISO-8859-1"?> <web-app 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/web-app_2_4.xsd" version="2.4"> <display-name>Repository</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>AxisServlet</servlet-name> <display-name>Apache-Axis Servlet</display-name> <servlet-class> org.apache.axis.transport.http.AxisServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <resource-ref> <description>Connection to my DB.</description> <res-ref-name>jdbc/Repository</res-ref-name> <res-type>javax.sql.DataSource </res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>
applicationContext.xml:Code:<Context path="/repository" docBase="repository" debug="1" reloadable="true" crossContext="true"> <Resource name="jdbc/Repository" auth="Container" scope="Shareable" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/test?autoReconnect=true"/> </Context>
Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/Repository"/> </bean> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource"/> </property> <property name="mappingResources"> <list> <value>org/psygrid/data/model/hibernate/Persistent.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> <bean id="dataSetDAO" class="org.psygrid.data.dao.hibernate.DataSetDAOHibernate"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> </beans>


Reply With Quote