I am trying to inject a DAO into a CXF service. For this, I use the xml configuration.
In my app-servlet.xml, I added the following entry:
<bean id="blogService" class="blog.BlogEntriesImpl"> <property name="blogDao" ref="blogDao" /> </bean>
blogDao bean is also defined in this file.
The service is configured in another XML file:
<import resource="classpath:META-INF/cxf/cxf.xml" /> <jaxws:endpoint id="blogService" implementor="blog.BlogEntriesImpl" address="/Blog1" />
BlogEntriesImpl implements the service interface. It has a dao attribute and a setter method.
I debugged the application and found out that one instance of BlogEntriesImpl started from the very beginning and had the dao attribute. I would say that this is done using the bean configuration from app-servlet.xml.
However, when I call the service, a NullPointerException is thrown. Here is another example of using BlogEntriesImpl.
To solve the problem, I declared the dao attribute in the service implementation class (BlogEntriesImpl) static. The variable is set at the beginning of the application. But I do not like it.
Is there a better way to embed dao in a CXF service?
Thank you in advance!
source share