> Hello, > > > I would like to read a properties file and get configuration information to > feed into my web service (all of this inside a tomcat container). > > I have a hello world web service and I would like to read a properties file > and respond with something inside it. How do I get the servlet context from > inside a CXF web service? > > I can also configure this as a Spring bean with properties set in the > configuration file. I don't know how to get the spring context either.. > > Can someone provide a hint? > > R. > > I guess you mean this?
Filename:service_ws.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:wsa="http://cxf.apache.org/ws/addressing" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>${jboss.server.config.url}/props/myprops.properties</value> </property> </bean> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <bean id="dbConnection" class="a.b.c.DBConnection"> <property name="jdbcDriver" value="${one.two.jdbc.driver}"/> <property name="jdbcUrl" value="${one.two.jdbc.url}"/> <property name="jdbcUser" value="${one.two.jdbc.user}"/> <property name="jdbcPwd" value="${one.two.jdbc.password}"/> </bean> and so on... You see, the properties file 'myprops.properties' is accesible over the predefined JBOSS property '${jboss.server.config.url}'. But the use of the JBOSS property is of course optional. Any valid path suffices. After the property file is read, the property values are directly usable for initialising your beans, i.e. : <property name="jdbcDriver" value="${one.two.jdbc.driver}"/> The above file is referred to in web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebService" version="2.5"> <display-name>WebService</display-name> <description>WebService</description> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/service_ws.xml</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>WebService</param-value> </context-param> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app> So during startup the whole mess is activated... Bye, Harry van Rijn
