org.springframework.beans.InvalidPropertyException错误调试

本文介绍了解决在Java Web项目中使用SSH框架时遇到的org.springframework.beans.InvalidPropertyException错误的方法。主要从spring配置文件中的属性变量一致性、getter/setter方法的实现及变量命名规则等方面进行分析。

org.springframework.beans.InvalidPropertyException

org.springframework.beans.InvalidPropertyException错误调试,它是我在写Javaweb项目用ssh,时遇到的错误。

出现这个错误主要原因有以下三点:

1、spring的配置文件中的属性变量名要一致。

2、要加入相应的get/set方法。

3、总是报这错误,仔细检查了配置,又没有问题的。原来好像是spring的命名规定第一个大写字母前必须有不少于2个的小写字母。

注意:要格外注意第3点。

最终我找到了我的错误,是出在string的命名规则:我没有写大写字母,全是小写字母。


//在WEB-INF目录下添加spring配置文件applicationContext.xml,用于注入bean等 ,这一步

//里面的applicationContext.xml的spring注入的name=“ ”写错。

在我写的applicationContext.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" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">


<bean id="productAction" class="action.ProductAction" scope="prototype">
<property name="productService" ref="productService"></property>
</bean> 


<bean id="productService" class="service.ProductService">
<property name="productDao" ref="productDao"></property>
</bean>
<bean id="productDao" class="dao.ProductDao">
</bean>


</beans>

测试Struts2和Spring框架是否整合成功 
项目右键->Run As->Run on Server,选择好tomcat容器运行。在浏览器地址栏输入:http:localhost:8080/EmployeeManagementSystem/addProduct.jsp 
如果弹出页面: 

这里写图片描述



我的这个项目运行结果:


springboot项目单元测试时,报java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@727320fa testClass = com.example.lpro.mybatisPlus.api.SyUserControllerTest, locations = [], classes = [com.example.lpro.LProApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [[ImportsContextCustomizer@2935fd2c key = [@org.springframework.context.annotation.Import(value={org.mybatis.spring.annotation.MapperScannerRegistrar.class}), @org.mybatis.spring.annotation.MapperScan(annotationClass=java.lang.annotation.Annotation.class, basePackageClasses={}, basePackages={"com.example.lpro.mapper"}, defaultScope="", factoryBean=org.mybatis.spring.mapper.MapperFactoryBean.class, lazyInitialization="", markerInterface=java.lang.Class.class, nameGenerator=org.springframework.beans.factory.support.BeanNameGenerator.class, processPropertyPlaceHolders=true, sqlSessionFactoryRef="", sqlSessionTemplateRef="", value={"com.example.lpro.mapper"}), @org.springframework.boot.test.context.SpringBootTest(args={}, classes={}, properties={}, useMainMethod=NEVER, value={}, webEnvironment=MOCK), @org.apiguardian.api.API(consumers={"*"}, since="5.0", status=STABLE), @org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class)]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@68c9133c, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5b218417, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@6c284af, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@6be968ce, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@1033576a, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@6c4906d3, org.springframework.boot.test.context.SpringBootTestAnnotation@129c1300], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null] 请帮我分析错误原因
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值