偶买嘎的!继续struts2+spring整合问题!!虚心求教!
解决了一个问题,又来了个问题 头痛中 ! 求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 帮帮我这个新手吧~~~
[解决办法]
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