2016-10-28 15 views
1

私はspringboot 1.4でGORM6を使用して、概念証明プロジェクトで問題を突きつけようとしています。完全なプロジェクトコードはavailable hereです。Gorm6とSpringboot 1.4を使用したIllegalArgumentException

私はbootRunを使用してプロジェクトを実行し、カール

$カールlocalhostを実行します:しようとすると、8080 /人/ -XのPUTは、 "lastNameの= DOE & firstNameの=ジョン"

を-dをhibernate/gormはIllegalArgumentExceptionをスローしています。

サーブレットのサーブレット[ディスパッチャサーブレット]パスワード付きのオンテキスト []投げられた例外[要求の処理に失敗しました。ネストされた例外は です。org.springframework.orm.hibernate5.HibernateSystemException: IllegalArgumentExceptionが発生しました。ゲッターの呼び出しが です。gorm.springboot.demo.model.Person.id;ネストされた例外は org.hibernate.PropertyAccessExceptionです:はIllegalArgumentException は 根本原因のjava.lang.IllegalArgumentExceptionがでgorm.springboot.demo.model.Person.id]のゲッターを呼び出す発生しました:オブジェクトが宣言クラス

の インスタンスではありません

本当に奇妙なのは、同じサービスを呼び出して渡すテストがあるため、RestController/Serviceの設定が間違っているかどうかはわかりません。

メイン:

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

モデルクラス:

@Entity 
class Person { 
    String lastName 
    String firstName 
} 

のcontrolerクラス:

@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 
    } 
} 

任意の洞察力をいただければ幸いです。

+0

休止状態についてはわかりません。しかし確かに、 'PersonService'のメソッドに問題があるようでした。 'get(id)'は 'Person'クラスの' static'メソッドではありません。 – Rao

+0

GORMは面白いですが、GORMは@Entityとして注釈が付けられたオブジェクトにこれらのメソッドを動的に追加します。 –

+0

'id'はどこから来ますか?または '@ Entity'からも来ていますか? – Rao

答えて

0

6.0.4のドキュメントで問題が特定されました。さらにspringboot-デベロッパーツール

@JsonIgnoreProperties(['dirtyPropertyNames', 'errors', 'dirty', 'attached', 'version'])

springbootを使用している場合、この注釈を追加する必要が+ GORM私は今、作業バージョンであることをgithubの上で自分のプロジェクトを更新休止5との継続的な問題があります。

関連する問題