【发布时间】:2017-10-29 22:32:05
【问题描述】:
当我尝试使用 springboot + JPA + kotlin + maven 时出现此异常
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: @Bean method 'init' must not be private or final;
change the method's modifiers to continue
Offending resource: com.wirecard.kotlin.jpa.Application
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.context.annotation.BeanMethod.validate(BeanMethod.java:50)
at org.springframework.context.annotation.ConfigurationClass.validate(ConfigurationClass.java:219)
at org.springframework.context.annotation.ConfigurationClassParser.validate(ConfigurationClassParser.java:528)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:307)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at com.wirecard.kotlin.jpa.ApplicationKt.main(Application.kt:50)
我按照此链接中的示例进行操作,但它是使用 Gradle 构建的
代码由3个类组成
类客户
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
@Entity
class Customer(
val firstName: String,
val lastName: String,
@Id @GeneratedValue(strategy = GenerationType.AUTO)
val id: Long = -1) {
override fun toString(): String {
return "Customer(id=$id, firstName='$firstName', lastName='$lastName')"
}
}
类 CustomerController
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
@RestController
class CustomerController(val repository:CustomerRepository) {
@GetMapping("/")
fun findAll() = repository.findAll()
@GetMapping("/{lastName}")
fun findByLastName(@PathVariable lastName:String)
= repository.findByLastName(lastName)
}
接口 CustomerRepository
>import org.springframework.data.repository.CrudRepository
interface CustomerRepository : CrudRepository<Customer, Long> {
fun findByLastName(lastName: String): Iterable<Customer>
}
【问题讨论】:
标签: spring maven jpa spring-boot kotlin