私は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
}
}
任意の洞察力をいただければ幸いです。
休止状態についてはわかりません。しかし確かに、 'PersonService'のメソッドに問題があるようでした。 'get(id)'は 'Person'クラスの' static'メソッドではありません。 – Rao
GORMは面白いですが、GORMは@Entityとして注釈が付けられたオブジェクトにこれらのメソッドを動的に追加します。 –
'id'はどこから来ますか?または '@ Entity'からも来ていますか? – Rao