Spring Rest CXF [bean 错误] Tomcat
我正在rest、spring、cxf和tomcat中做一个网络服务。
链接完整项目: http://www55.zippyshare.com/v/99585767/file.html
我在 bean 上遇到了这个错误。 无法弄清楚为什么会发生这种情况?
严重:上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名称为“restContainer”的bean时出错:使用键[0]设置bean属性“serviceBeans”时无法解析对bean“timeService”的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为“timeService”的bean
在 org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
在 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>
这些是我的文件,我无法找出问题所在。这让我抓狂!
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 reference 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring 文档 说您需要添加一个元素来指导查找带有
@Service
注释的 bean。例如,如果您的 bean 位于包org.example
或其子包之一中,则您可以在 beans.xml 中使用组件扫描器配置,如下所示:(只要它位于
元素,无论它位于
元素之上还是之下都可以。)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 packageorg.example
or one of its sub-packages, you'd use a component scanner configuration in your beans.xml like this:(As long as it's inside the
<beans>
element, it's fine whether it goes above or below the<jaxrs:server>
element.)