Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step4有点问题 #18

Open
CH0918 opened this issue Nov 8, 2018 · 1 comment
Open

step4有点问题 #18

CH0918 opened this issue Nov 8, 2018 · 1 comment

Comments

@CH0918
Copy link

CH0918 commented Nov 8, 2018

作者用来做测试用的类HelloWorldService里面只有简单的一个字段String text;这时候从tinyioc.xml中解析后的属性为字符串型,利用反射将解析后的tinyioc.xml中的属性”text“属性注入是没问题的,但是如果我用来做测试的类有其他类型的成员变量,比如我要测试的对象是User,有一个类型为Integer的age成员变量,这时候从xml解析出来的属性由于全都是String型,用反射向User中的age注入属性会报java.lang.IllegalArgumentException类型转换异常。
反正总结起来的问题就是作者测试用的类只能注入String类型的字段,其他类型好像注入不了。

@HuangtianyuCN
Copy link

这个代码里面有体现,在XmlBeanDefinitionReader的processProperty方法中,读取xml是把value所对应的值直接赋给成员变量的。这边可以自己改的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants