偶买嘎的!继续struts2+spring整合问题!!虚心求教!

tutty 2011-09-24 06:18:58
解决了一个问题,又来了个问题 头痛中 ! 求j2ee帝解围!

以下是异常
---------------------------------------------------
信息: Loading Spring root WebApplicationContext
2011-9-24 18:04:31 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginaction' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Loginsevice' of bean class [org.xy.action.LoginAction]: Bean property 'Loginsevice' is not writable or has an invalid setter method. Did you mean 'loginservice'?
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'Loginsevice' of bean class [org.xy.action.LoginAction]: Bean property 'Loginsevice' is not writable or has an invalid setter method. Did you mean 'loginservice'?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:751)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:608)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:970)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:729)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:416)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-9-24 18:04:31 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2011-9-24 18:04:31 org.apache.catalina.core.StandardContext start
严重: Context [/SSproject] startup failed due to previous errors
2011-9-24 18:04:31 org.apache.catalina.core.ApplicationContext log

--------------------------------------
以下是ApplicationContext.xml
--------------------------------------
<bean id="Loginservice" class="org.xy.service.LoginServiceimpl">
</bean>


<bean id="loginaction" class="org.xy.action.LoginAction">
<property name="Loginsevice">
<ref local="Loginservice"/>
</property>

</bean>
---------------------------------------
以下是struts.xml
---------------------------------------
<struts>
<constant name="struts.devMode" value="true"/>
<package name="demo" extends="struts-default">



<action name="LoginAction" class="loginaction">
<result name="success">/success.jsp</result>
<result name="input">/index.jsp</result>
</action>

</package>
</struts>
-----------------------------------------
以下是LoginAction.java
-----------------------------------------
public class LoginAction extends ActionSupport {

public String username;
public String password;
public String message;

private LoginService Loginservice;

public LoginService getLoginservice() {
return Loginservice;
}

public void setLoginservice(LoginService loginservice) {
Loginservice = loginservice;
}

public String execute() throws Exception {
/*if("xy".equalsIgnoreCase(username)&&"xy".equalsIgnoreCase(password))
{
return SUCCESS;



}
else
{
message= " login failed." ;
return INPUT;
}*/
if(
this.getLoginservice().login(username, password)==true)
return SUCCESS;
return INPUT;


}
----------------------------------------------------------
T.T 帮帮我这个新手吧~~~
...全文
159 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
tutty 2011-09-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 redlotus_lyn 的回复:]

struts2整合spring步骤:

1.需要spring相关jar包。

2.struts2配置属性:
struts.objectFactory = spring
struts.objectFacotry.spring.autowire = name

3.配置web.xml
1>.spring监听器
2>.spring配置文件位置(可选)。

4.applicati……
[/Quote]

谢谢 小弟刚学菜鸟 加你Q 以后请多多指教
丶蒙圈丶 2011-09-27
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 comaple 的回复:]

你的配置没有错的,关键是属性的问题,应该是你写错了,楼上得兄弟说的对,你看段异常:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Loginsevice' of bean class [org……
[/Quote]

+++
webrobot 2011-09-27
  • 打赏
  • 举报
回复
是的。属性写错了。这东西要细心点。成功之后,以后基本复制自己的就不会出错了。

刚开始做例子,最好越小越好。
  • 打赏
  • 举报
回复
这个应该是命名的问题,虽然你在类中写的是 Loginservice这个属性,但是不是直接访问的Loginservice属性,而是用的get set方法,根据命名规范,他去找的是loginservice,大写的自然错了
bijanen19861113 2011-09-26
  • 打赏
  • 举报
回复
<bean id="loginaction" class="org.xy.action.LoginAction">
<property name="Loginsevice">
这里的name值要和action类中的private LoginService Loginservice;
中的Loginservice完全一致。
你现在写的不一致,所以出错了..
康派尔 2011-09-26
  • 打赏
  • 举报
回复
你的配置没有错的,关键是属性的问题,应该是你写错了,楼上得兄弟说的对,你看段异常:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Loginsevice' of bean class [org.xy.action.LoginAction]: Bean property 'Loginsevice' is not writable or has an invalid setter method. Did you mean 'loginservice'?
「已注销」 2011-09-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tutty 的回复:]
引用 3 楼 scrack 的回复:

<bean id="loginaction" class="org.xy.action.LoginAction">
<property name="Loginsevice">
<ref local="Loginservice"/>

写错了


应该怎么改呀?
[/Quote]


LoginService单词写错了,少个“r”
夕水溪下 2011-09-26
  • 打赏
  • 举报
回复
Error creating bean with name 'loginaction' defined in ServletContext resource

很明显,IOC或者DI错误!检查命名
wzy42563 2011-09-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 scrack 的回复:]

<bean id="loginaction" class="org.xy.action.LoginAction">
<property name="Loginsevice">
<ref local="Loginservice"/>

写错了
[/Quote]
+1
redlotus_lyn 2011-09-25
  • 打赏
  • 举报
回复
struts2整合spring步骤:

1.需要spring相关jar包。

2.struts2配置属性:
struts.objectFactory = spring
struts.objectFacotry.spring.autowire = name

3.配置web.xml
1>.spring监听器
2>.spring配置文件位置(可选)。

4.applicationContext.xml中配置

<beans default-autowire="byName">
<bean id="loginAction" class="org.xy.action.LoginAction" />
<bean id="loginService" class="org.xy.service.LoginServiceimpl" />
</beans>

5.action中使用Service
private LoginServiceimpl loginService;
loginService有set方法。

如果以上不能解决你的问题,QQ:75425364
tutty 2011-09-24
  • 打赏
  • 举报
回复
= =有人瓦??
tutty 2011-09-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 scrack 的回复:]

<bean id="loginaction" class="org.xy.action.LoginAction">
<property name="Loginsevice">
<ref local="Loginservice"/>

写错了
[/Quote]

应该怎么改呀?
scrack 2011-09-24
  • 打赏
  • 举报
回复
<bean id="loginaction" class="org.xy.action.LoginAction">
<property name="Loginsevice">
<ref local="Loginservice"/>

写错了
tutty 2011-09-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yexiongmybh 的回复:]

private LoginService Loginservice;
我觉得就是这个命名错了,,一般命名规则是
private LoginService loginService;
然后自动生成get和set方法。那样才正确。

你修改成那样试试看,看异常代码就是这个loginService的注入有问题。其他配置文件看着貌似没什么问题的。
[/Quote]
不行额 还是一样的问题 我知道是spring配置文件问题,但是不知道该怎么改。。
yexiongMYBH 2011-09-24
  • 打赏
  • 举报
回复
private LoginService Loginservice;
我觉得就是这个命名错了,,一般命名规则是
private LoginService loginService;
然后自动生成get和set方法。那样才正确。

你修改成那样试试看,看异常代码就是这个loginService的注入有问题。其他配置文件看着貌似没什么问题的。

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧