---
title: "关于使用Spring的BeanUtils复制属性时Boolean类型无法复制的问题"
author: "buddie"
date: "2019-03-29T16:32:06Z"
tags: []
categories: ["编程语言"]
slug: "spring-beanutils-boolean"
draft: false
lastmod: "2019-03-29T16:32:06Z"
id: 2439537
url: "https://buddie.iteye.com/blog/2439537"
---

spring-beans版本5.0.12

JDK版本1.8.0\_181

 

使用BeanUtils.copyProperties(Object source, Object target)进行属性复制时，遇到了Boolean类型无法复制的问题，一步步的跟进了java的rt.jar包中的Instrospector类中，发现第513行只认boolean类型

```
if (argCount == 0) {
                        if (name.startsWith(GET_PREFIX)) {
                            // Simple getter
                            pd = new PropertyDescriptor(this.beanClass, name.substring(3), method, null);
                        } else if (resultType == boolean.class && name.startsWith(IS_PREFIX)) {
                            // Boolean getter
                            pd = new PropertyDescriptor(this.beanClass, name.substring(2), method, null);
                        }
                    }
```

 

所以，是不支持Boolean类型的复制，只支持boolean类型的复制