Tag: 春季启动

在Spring WebFlux中实现Spring Cloud Sleuth的TracingWebFillter

我有一个使用Spring Cloud Sleuth的function端点(Kotlin)的Spring Boot Reactive应用程序。 我想自定义响应标题以包含跟踪标识。 我看了一下手册,看到使用TraceFilter的部分: 1 我试图使用TraceWebFilter做同样的事情,但它不公开构造函数。 有什么方法可以在使用Reactive Web Framework时实现这个定制。 我为Spring Cloud Sleuth使用了2.0.0.M5版本 提前致谢!

hibernate没有正确构建查询

我的项目是用Spring Boot和Kotlin构建的。 我有一个Message ,可能有一个父消息(当回应消息),代码如下所示: @Entity class Message( @field: Id @field:GeneratedValue var id : Long = 0, @field: ManyToOne(targetEntity = Employee::class) var sender:Employee?=null, @field: ManyToOne(targetEntity = Employee::class) var receiver:Employee?=null, var time:LocalDateTime, var content: String, var read:Boolean, @field: ManyToOne(targetEntity = Message::class) @Nullable var father:Message?=null) {} 当调用这个查询(使用JpaRepository)时: fun findByReceiverIdAndReadFalse(id:Long):List 我得到这个错误: Unknown column ‘message0_.father_id’ in ‘field list’ 它实际上应该是message0_.father.id ,而不是father_id […]

在tornadofx中使用localdatetime和其余的springboot

我开发了一个带有springboot rest服务的tornadofx应用程序作为后端 所有在kotlin语言 问题是tornadofxSeNd LocalDateTime作为Int这会导致这个错误在springboot服务器 2018-01-31 18:33:31.296 WARN 11473 — [nio-8080-exec-2] .wsmsDefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected token (VALUE_NUMBER_INT), expected VALUE_STRING: Expected array or string.; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (VALUE_NUMBER_INT), expected VALUE_STRING: Expected array or string. at [Source: (PushbackInputStream); line: 1, column: 16] (through reference chain: andalous.torndadoserver.financial.dailymove.newDailyMove[“date”]) […]

如何将此Java代码转换为Kotlin代码?

我正在学习春季引导和新kotlin。 此Java函数转换为kotlin代码时将报告错误。 如何重写这个kotlin函数? https://spring.io/guides/gs/consuming-rest/ @Bean public CommandLineRunner run(RestTemplate restTemplate) throws Exception { return args -> { Quote quote = restTemplate.getForObject( “http://gturnquist-quoters.cfapps.io/api/random”, Quote.class); log.info(quote.toString()); }; } 将这些代码转换成kotlin后, @Bean @Throws(Exception::class) fun run(restTemplate: RestTemplate): CommandLineRunner { return { args -> val quote = restTemplate.getForObject( “http://gturnquist-quoters.cfapps.io/api/random”, Quote::class.java) log.info(quote.toString()) } } 请告诉我如何更正此代码。

如何用Spring WebFlux返回404

我有一个这样的控制器(在Kotlin中): @RestController @RequestMapping(“/”) class CustomerController (private val service: CustomerService) { @GetMapping(“/{id}”) fun findById(@PathVariable id: String, @RequestHeader(value = IF_NONE_MATCH) versionHeader: String?): Mono<HttpEntity> = return service.findById(id) .switchIfEmpty(Mono.error(NotFoundException())) .map { // ETag stuff … ok().eTag(“…”).body(…) } } 我想知道是否有一个更好的方法比抛出一个exception是用@ResponseStatus(code = NOT_FOUND)注解@ResponseStatus(code = NOT_FOUND)

ErrorPageFilter – 无法转发到错误页面的请求

我经常在运行的服务器上看到这样的错误日志: 错误osboot.web.support.ErrorPageFilter – 由于响应已经提交,无法转发到请求[/ api / login]的错误页面。 因此,响应可能有错误的状态码。 如果您的应用程序在WebSphere Application Server上运行,则可以通过将com.ibm.ws.webcontainer.invokeFlushAfterService设置为false来解决此问题 我的服务器运行和开发环境: Ubuntu 14.04 Tomcat 8 Sprint Framework: 4.3.1 Sprint Boot: 1.5.9 Kotlin: 1.2.21 根据stackoverflow中的一个问题 ,我添加了下面的代码(转换为Kotlin代码)尝试删除此错误日志,但不起作用。 @SpringBootApplication @EnableScheduling @EnableAsync @EnableTransactionManagement open class MyApplication: SpringBootServletInitializer() { init { setRegisterErrorPageFilter(false) <<<< I added this func call to try fix } companion object { @JvmStatic fun main(args: Array) […]

Spring引导+ kotlin runApplication (* args)无法启动

import org.springframework.boot.runApplication import org.springframework.boot.SpringApplication @SpringBootApplication open class MyApplication fun main(args: Array) { runApplication(*args) } 错误:无法find或无法加载主类 为什么不能运行,但这可以吗? import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.SpringApplication @SpringBootApplication open class MyApplication fun main(args: Array) { SpringApplication.run(MyApplication::class.java, *args) }

在spring kotlin支持中指定默认autowireMode的方法

Spring引导版本2,Spring框架版本5。 如何为beans DSL指定默认的autowireMode ? 我目前使用这个每个bean: fun beans() = org.springframework.context.support.beans { bean(autowireMode = BeanDefinitionDsl.Autowire.BY_NAME) bean(autowireMode = BeanDefinitionDsl.Autowire.BY_NAME) // hundreds more bean } 这是乏味的。 bean实现来自传统应用程序,所以我不能使用Component 。

在Kotlin中创建来自Spring配置的列表的映射

我正在尝试在Kotlin编写的Spring Boot应用程序中创建Map<String, List>types的对象。 我能够从配置创建一个映射,也能够从配置创建一个列表,但是当我尝试并结合这两个我得到以下exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘myConfiguration’: Could not bind properties to MyConfiguration (prefix=, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is java.lang.NullPointerException 我的Configuration Object : @ConfigurationProperties @Component class MyConfiguration { var myNewMap: Map<String, List>? = null } 我的Configuration yml : — myNewMap: firstKey: – 2 – 4 secondKey: – 2 这是可能的方式在阅读配置的Spring? 或者是唯一的方法来创建一个简单的地图的值作为一个逗号分隔的字符串,并把它变成我的应用程序中的列表? […]

如何将@Value属性注入到使用Spring 5和Kotlin Bean Definition DSL定义的bean中

我正在开发一个使用Kotlin的Spring Boot(2.0.0 M7)应用程序,并且需要定义一些bean来利用新的DSL来定义bean。 我不能想出一个方法来注入来自@Value属性的值。 我们来考虑这个简化的例子: fun beans() = beans { for (i in 1..10) { bean(“myString${i}” + someProperty) { “myString${i}” + someProperty} } } someProperty应该来自这样的东西: @Value(“\${myProperty}”) someProperty: String 我如何使它可以访问beans {} DSL?