java - Inject DAO into CXF Service -


i trying inject dao cxf service. purpose using xml configuration.

in app-servlet.xml i've added following entry:

 <bean id="blogservice" class="blog.blogentriesimpl"> <property name="blogdao" ref="blogdao" /> </bean> 

blogdao bean defined in file.

the service configured in xml file:

 <import resource="classpath:meta-inf/cxf/cxf.xml" /> <jaxws:endpoint id="blogservice" implementor="blog.blogentriesimpl" address="/blog1" /> 

blogentriesimpl implements service interface. has dao attribute , setter method.

i debugged application , found out, 1 instance of blogentriesimpl instanciated on start , has dao attribute. done bean configuration app-servlet.xml.

however, when call service, nullpointerexception thrown. here instance of blogentriesimpl being used.

to solve problem declared dao attribute in service implementation class (blogentriesimpl) static. variable set on start of application. don't solution.

is there better way inject dao cxf service?

thank in advance!

you right, there 2 instances of blogentriesimpl class, 1 created spring , 1 apache cxf. must explicitly ask apache cxf use spring bean rather providing class. check out writing service spring, looks have replace:

<jaxws:endpoint id="blogservice" implementor="blog.blogentriesimpl" address="/blog1" /> 

with:

<jaxws:endpoint id="blogservice" implementor="#blogservice" address="/blog1" /> 

if apache cxf can't find bean name blogservice, consider moving main context spring mvc context (app-servlet.xml).


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -