Kit*_*Cat 7 java spring kotlin spring-boot
我正在尝试使用 Spring Boot 在 Kotlin 中进行配置data class
。我有以下课程:
@Configuration
@ConfigurationProperties(prefix = "spring.braintree")
data class BraintreeConfigProperties(
val merchantId: String = "",
val publicKey: String = "",
val privateKey: String = "",
val environment: Environment = Environment.SANDBOX
)
Run Code Online (Sandbox Code Playgroud)
以及以下属性:
spring.braintree.merchantId=${BRAINTREE_MERCHANT_ID}
spring.braintree.publicKey=${BRAINTREE_PUBLIC_KEY}
spring.braintree.privateKey=${BRAINTREE_PRIVATE_KEY}
Run Code Online (Sandbox Code Playgroud)
当我运行该应用程序时,出现以下异常:
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.braintree' to com.x.ps.config.BraintreeConfigProperties$$EnhancerBySpringCGLIB$$311e0531:
Property: spring.braintree.merchant-id
Value: ${BRAINTREE_MERCHANT_ID}
Origin: class path resource [application.properties] - 5:29
Reason: java.lang.IllegalStateException: No setter found for property: merchant-id
Action:
Update your application's configuration
Run Code Online (Sandbox Code Playgroud)
不过,我也有一个和班级一模一样的班级BraintreeConfigProperties
。这个类(DatabaseConfigProperties
)确实有效。它们是完全相同的。
我尝试过的:
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.braintree' to com.x.ps.config.BraintreeConfigProperties$$EnhancerBySpringCGLIB$$62509e61:
Property: spring.braintree.merchant-id
Value: 1234
Origin: class path resource [application.properties] - 5:29
Reason: java.lang.IllegalStateException: No setter found for property: merchant-id
Action:
Update your application's configuration
Run Code Online (Sandbox Code Playgroud)
Oli*_*ahl 13
这里的问题是val
最终的并且var
可以改变。所以你应该将你的属性更改为var
.
更多信息:https://medium.com/mindorks/kotlin-series-val-vs-var-difference-android-kotlin-ecad780daeb7
归档时间: |
|
查看次数: |
7281 次 |
最近记录: |