在springMVC项目启动的时候报错了,如下面所示:
- 严重: Context initialization failed
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/springMVC-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [com.spw.service.UserService]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
- at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
- at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
- at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
- at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
- at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
- at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
- at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
- at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
- at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
- at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
- at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
- at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
- at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
- 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(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
- at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
- Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [com.spw.service.UserService]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
- at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
- at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:924)
- at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
- at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
- ... 37 more
- 2016-6-6 22:50:07 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 'userService' defined in ServletContext resource [/WEB-INF/springMVC-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [com.spw.service.UserService]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
- at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
- at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
- at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
- at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
- at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
- at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
- at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
- at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
- at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
- at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
- at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
- at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
- at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
- 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(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
- at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
- Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [com.spw.service.UserService]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
- at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
- at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:924)
- at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
- at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
- ... 37 more
可以看到:Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [com.spw.service.UserService]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method
这条引起错误的原因,根据这条错误信息可以得到
1:错误的属性名称jdbcTemplate 2:jdbc是不可写的或者有一个错误的setter方法,
对应的解决办法有:
1:看jdbcTemplate的名称是否正确,看你service实现方法中private JdbcTemplate jdbcTemplate这个名称是否对应
2:看的成员变量jdbcTemplate是否有setter方法,没有补上
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }