我有一个字符串类型就像一个计时:"2015-01-05 17:00"
和ZoneId
是"Australia/Sydney"
.
如何使用Java 8 datetime API将此时间信息转换为对应的UTC时间?
还需要考虑DST的东西.
我刚刚意识到,对于Grails控制器,还有另一种渲染方法"响应".
如果我们想在控制器中渲染视图,则response和render方法之间有什么区别.
我想向我的play项目介绍一下slick,所以我将以下依赖项添加到build.sbt:
"com.typesafe.play" %% "play-slick" % "1.0.1" withSources(),
"com.typesafe.play" %% "play-slick-evolutions" % "1.0.1" withSources(),
Run Code Online (Sandbox Code Playgroud)
然后,当我运行控制器的集成规范时,我在Intellij IDE和命令行激活器测试中都遇到了异常.谷歌之后我找到了解决方案:https://www.playframework.com/documentation/2.4.x/PlaySlickFAQ#A-binding-to-play.api.db.DBApi-was-already-configured
我删除了jdbc依赖项后,在使用命令行时传递了集成规范,但是当我在Intellij IDE上运行测试时仍然遇到同样的错误,如下面的错误:在嵌套套件上调用run时遇到异常 - 无法创建注入器,请参阅以下错误:
1) A binding to play.api.db.DBApi was already configured at play.api.db.DBModule.bindings(DBModule.scala:25):
Binding(interface play.api.db.DBApi to ProviderConstructionTarget(class play.api.db.DBApiProvider)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1).
at play.api.db.slick.evolutions.EvolutionsModule.bindings(EvolutionsModule.scala:15):
Binding(interface play.api.db.DBApi to ConstructionTarget(class play.api.db.slick.evolutions.internal.DBApiAdapter) in interface javax.inject.Singleton) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
1 error
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) A binding to play.api.db.DBApi was already configured at play.api.db.DBModule.bindings(DBModule.scala:25):
Binding(interface play.api.db.DBApi …
Run Code Online (Sandbox Code Playgroud) 我想知道有一种方法可以在创建问题时自动创建子任务.
例如,我创建自定义标准问题类型,XXX和子任务问题类型YYY和ZZZ.当我创建类型为XXX的问题时,将自动创建具有相应问题类型YYY和ZZZ的两个子任务.
在Java8之前,我使用Joda的DateTime
类来包含时区信息,我可以轻松地在DateTime
sql和sql 之间进行转换Timestamp
.
迁移到Java8后,我应该替换哪个类?OffsetDateTime
还是ZonedDateTime
?
另外,我试图使用OffsetDateTime
,但似乎无法OffsetDateTime
从sql 构造回来Timestamp
.
对于Joda DateTime
和Timestamp
转换器,代码如下:
val joda = DateTime.now()
val sqlJoda = new Timestamp(joda.getMillis)
val jodaBack = new DateTime(sqlJoda)
Run Code Online (Sandbox Code Playgroud)
但对于Java8,
val java8 = OffsetDateTime.now()
val sqlJava8 = new Timestamp(java8.toInstant.toEpochMilli)
val java8Back = ???
Run Code Online (Sandbox Code Playgroud)
有人对此有所了解吗?看来Joda DateTime
真的很棒.
首先,如果我想将带有时区的日期时间映射到Slick,我应该使用哪个类OffsetDateTime
或ZonedDateTime
?至于Joda,我们只能使用DateTime
.
我怎么能写一些隐式的转换java8 ZonedDateTime
和Sql 之间Timestamp
的Slick表映射?
使用joda DateTime
来包含时区信息似乎非常简单.但是一旦切换到Java8,不太确定我是否应该使用ZonedDateTime
或者OffsetDateTime
,因为http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html建议使用OffsetDateTime.
对于我当前的代码,我只是使用Java8 LocalDateTime
,我写下隐含的光滑映射.
implicit val JavaLocalDateTimeMapper = MappedColumnType.base[LocalDateTime, Timestamp](
l => Timestamp.valueOf(l),
t => t.toLocalDateTime
)
Run Code Online (Sandbox Code Playgroud)
不太清楚,我可以用任何写类似ZonedDateTime
或OffsetDateTime
?
我想用Kotlin读取yaml配置文件,下面是我的代码:
application.yml
message:
messages:
- name: abc
type: aaa
size: 10
- name: xyz
type: bbb
size: 20
Run Code Online (Sandbox Code Playgroud)
MessageConfig.kt
package com.example.demokotlin
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import java.math.BigDecimal
@ConfigurationProperties(prefix = "message")
@Configuration
class MessageConfig {
lateinit var messages: List<Message>
}
class Message {
lateinit var name: String
lateinit var type: String
lateinit var size: BigDecimal
}
Run Code Online (Sandbox Code Playgroud)
要使用配置的类:
package com.example.demokotlin
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
@Component
class MessageService @Autowired constructor(private var messageConfig: MessageConfig) {
fun createMessage(): String {
println("in service........")
println(messageConfig.messages[0].name)
println(messageConfig.messages[0].type)
println(messageConfig.messages[0].size) …
Run Code Online (Sandbox Code Playgroud) 我正在为我的项目使用Resteasy和Spring.正如Resteasy文件所述:http://docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html_single/index.html#RESTEasy_Spring_Integration .
我需要在web.xml文件中添加一个监听器:
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
Run Code Online (Sandbox Code Playgroud)
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
Run Code Online (Sandbox Code Playgroud)
但是,在我的项目中,我们还使用了一个名为magnolia的cms,而magnolia也有一个SpringContextLoaderListener的实现.如果我把两个上下文监听器.当我运行应用程序时,玉兰花不会启动.
所以根据Resteasy的文件说:
如果不使用Spring ContextLoaderListener创建bean工厂,则可以通过分配org.jboss.resteasy.plugins.spring.SpringBeanProcessor的实例来手动注册RESTeasy BeanFactoryPostProcessor.您可以从ServletContext属性org.jboss.resteasy.spi.ResteasyProviderFactory和org.jboss.resteasy.spi.Registry获取ResteasyProviderFactory和Registry的实例.(真的是这些类的字符串FQN).还有一个org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware,它将自动从Servlet Context注入对Registry和ResteasyProviderFactory的引用.(也就是说,如果您使用RestasyBootstrap来引导Resteasy).
有没有人知道如何在不使用Resteasy ContextLoaderListener的情况下实现这一目标?我需要在spring applicationContext xml文件中添加什么内容?
我在Scala Play项目中使用了ScalaTest。但是我在这里有一个问题,什么时候使用普通的assert(xxx === yyy)
以及什么时候使用ScalaTest匹配器xxx should be yyy
。
就我个人而言,我更喜欢使用assert,因为它既简单又干净。也可以利用ScalaTest的TypedCheckTrippleEquals
支持,但匹配器则不能。
对于匹配器,到目前为止,我只发现匹配器可以做的一件事,但不能断言,这是Array(1, 2) should equal (Array(1, 2))
成功的。
不太确定推荐哪个,匹配器还有其他东西可以做得更多吗?否则很高兴使用断言。
我正在使用 Spring Kafka 消费者和 Avro 架构来构建我的应用程序。
但是,如果消息无法反序列化到我构建的指定 Avro 特定记录,则消费者将不断地一遍又一遍地重试消费相同的消息(无限重试)。
对于这种情况,如果我的消费者发生反序列化器异常,如何配置消费者应用程序以跳过当前消息并移至下一个偏移量。
我查看了 Spring Kafka 错误句柄,它只能处理侦听器中的异常,而不能处理反序列化阶段的异常。
我的消费者应用程序非常简单:
@KafkaListener(id = "demo-consumer-stream-group", topics = "customer-output-")
public void process(ConsumerRecord<String, Customer> record) {
LOGGER.info("Customer key: {} and value: {}", record.key(), record.value());
LOGGER.info("topic: {}, partition: {}, offset: {}", record.topic(), record.partition(), record.offset());
}
Run Code Online (Sandbox Code Playgroud)
基于此代码,有时接收到的消息可能无法反序列化为正确的Customer
对象。
另外,我看到最近的解决方案是使用ErrorHandlingDeserializer2
Spring Kafka 来处理这个问题,但是由于我正在使用KafkaAvroDeserializer
如何计算出这些配置?我当前的配置是:
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaAvroDeserializer.class);
Run Code Online (Sandbox Code Playgroud) java ×4
scala ×3
spring ×3
datetime ×2
java-8 ×2
slick ×2
apache-kafka ×1
grails ×1
java-time ×1
jira ×1
jira-plugin ×1
jodatime ×1
kotlin ×1
magnolia ×1
matcher ×1
resteasy ×1
scalatest ×1
spring-boot ×1
spring-kafka ×1
utc ×1