Spring Rest CXF [bean error] Tomcat
I´m doing a webservice in rest, spring, cxf and tomcat.
Link full project: http://www55.zippyshare.com/v/99585767/file.html
I´ve got this error on bean. Can´t figure out why is this happening?
SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restContainer': Cannot resolve ref开发者_JAVA技巧erence to bean 'timeService' while setting bean property 'serviceBeans' with key [0]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'timeService' is defined at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
timeService.java
@Service("timeService")
@Path("/time")
public class TimeService {
@GET
@Produces("text/plain")
public String getDateTime()
{
DateFormatter formatter = new DateFormatter("dd/MM/yyyy hh:mm:ss");
return formatter.print(Calendar.getInstance().getTime(), Locale.getDefault());
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<ref bean="timeService"/>
</jaxrs:serviceBeans>
</jaxrs:server>
</beans>
These are my files and i can´t find out what is wrong. This is driving me nuts!
The Spring documentation says that you need to add an element to direct the finding of your @Service
-annotated beans. For example, if your beans were in the package org.example
or one of its sub-packages, you'd use a component scanner configuration in your beans.xml like this:
<context:component-scan base-package="org.example"/>
(As long as it's inside the <beans>
element, it's fine whether it goes above or below the <jaxrs:server>
element.)
精彩评论