使用Gorm6&amp ;; IllegalArgumentException Springboot 1.4

时间:2016-10-28 15:07:09

标签: hibernate groovy spring-boot gorm

我正在尝试将GORM6与springboot 1.4一起用于概念验证项目并遇到问题。完整的项目代码为available here

我使用bootRun运行项目并运行curl

  

$ curl localhost:8080 / persons / -X PUT -d" lastName = doe& firstName = John"

当试图在我的其他控制器调用的服务中保存域类时,hibernate / gorm会抛出IllegalArgumentException

  

用于servlet [dispatcherServlet]的Servlet.service()与path的上下文   []引发异常[请求处理失败;嵌套异常是   org.springframework.orm.hibernate5.HibernateSystemException:   调用getter时出现IllegalArgumentException   gorm.springboot.demo.model.Person.id;嵌套异常是   org.hibernate.PropertyAccessException:IllegalArgumentException   发生了调用gorm.springboot.demo.model.Person.id的getter   root cause java.lang.IllegalArgumentException:object不是   声明类

的实例

我真的很奇怪,我有一个调用相同服务并通过的测试,所以我不确定我的RestController / Service是否只是设置错误。

主:

@SpringBootApplication
@EnableTransactionManagement
class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main, args);
    }
}

模特课程:

@Entity
class Person {
    String lastName
    String firstName
}

控制器类:

@RestController()
@RequestMapping("/persons")
@Slf4j
class PersonController {

    @Autowired
    PersonService personService

    @RequestMapping(value="/", method = RequestMethod.GET)
    def list() {
        return personService.getAllPersons()
    }

    @RequestMapping(value="/", method= RequestMethod.PUT)
    def add(@RequestParam String lastName,@RequestParam String firstName) {
        log.info("received request for l=${lastName}, f=${firstName}")
        personService.save(new Person(lastName:lastName, firstName:firstName))

    }
}

服务类:

@Service('personService')
@Transactional
class PersonService {

    def getAllPersons() {
        return Person.list()
    }

    def save(Person p) {
        p.save(true)
    }

    def getPerson(long id) {
        return Person.get(id)
    }
}

最后我的测试通过了与我的休息控制器中的PUT方法基本相同的事情:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
class PersonSpec extends Specification {

    @Autowired PersonService personService

    def 'Persist a person'() {
        when: "Person to add"
        def p = new Person(lastName:"Rizzo", firstName:"Anthony")

        then: "Persist that person"
        personService.save(p)

        expect: "Person to be saved"
        personService.getAllPersons().size() > 0
        personService.getPerson(p.id).lastName == p.lastName
    }
}

任何见解都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

6.0.4的文档确定了该问题。使用springboot + gorm时需要添加此注释 @JsonIgnoreProperties(['dirtyPropertyNames','errors','dirty','attach','version']) 另外spring-boot-devtools与hibernate 5一直存在问题。我现在在github上更新了我的项目。