Tag: 弹簧启动

@DataJpaTest和@Async CRUDRepository方法不能一起工作

我目前使用spring-boot作为@Async实现了一些存储库方法,当我实际启动应用程序时,它的工作方式应该是这样,但是在运行集成测试时,事情开始变得很奇怪。 我已经设置了一个展示问题的小项目。 库: interface MyObjectRepository : CrudRepository<MyObject, Long> { @Async fun findBySomething(something: String): ListenableFuture<MyObject?> } 应用: @SpringBootApplication @EnableAsync class Application { private val log = LoggerFactory.getLogger(Application::class.java) } fun main(args: Array<String>) { SpringApplication.run(Application::class.java, *args) } 而我的测试案例: @RunWith(SpringRunner::class) @DataJpaTest class MyObjectRepositoryTest { @Autowired lateinit var target: MyObjectRepository @Before fun `init`() { target.deleteAll() } @Test fun `should be […]

通过外部配置通知命名策略

注意:这是一个Spring / Hibernate的问题。 我碰巧使用Kotlin,但也欢迎Java的答案。 JPA实体必须有一个常量表和目录名称: User.kt : @Entity @Table(name="users", catalog="auth") data class User( @Id val username: String, var password: String ) 这对我来说是个坏消息。 我的MySQL数据库托管同一个应用程序堆栈的几个不同的实例。 结果是:我有各种各样的模式,名字由环境隔开: SHOW DATABASES; sandbox_billing sandbox_auth staging_billing staging_auth preproduction_billing preproduction_auth 每个应用程序上下文都有一个数据源,可以访问两个目录: *_billing (用于域实体)和*_auth (用于身份验证信息)。 我的应用程序有一个可配置的映射com.stackoverflow.persistence.catalog-overrides ,其中可以指定用于该特定应用程序实例的目录名称: application.yml : spring: datasource: url: 'jdbc:mysql://mycooldatabase.com:3306' com.stackoverflow: persistence: catalog-overrides: billing: sandbox_billing auth: sandbox_auth 这个配置被填充到POKO中: PersistenceProperties.kt : @Component […]

在kotlin / spring引导中使用Gradle属性扩展

我目前正在使用gradle作为构建工具来构建Kotlin , Spring Boot服务。 我试图自动扩展在我的application.properties文件中找到的属性,使用在这里找到的步骤: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-automatic-expansion-gradle 我的版本如下: – kotlin: 1.1.4-3 – spring boot: 1.5.6.RELEASE – gradle: 3.5.1 当我运行./gradlew bootRun ,出现以下错误: java.lang.IllegalArgumentException: Could not resolve placeholder 'myServiceName' in value "${myServiceName}" 其次是: java.lang.IllegalStateException: LifecycleProcessor not initialized – call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@510aeb93: startup date [Fri Sep 15 10:59:51 AEST 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@68edf5bb […]

你如何设置Kotlin,Gradle和Web框架的Spring Loaded?

我是JVM新手,有兴趣尝试使用Kotlin进行REST风格的Web开发。 热重新加载是我习惯于从Python,Ruby和JavaScript等动态脚本语言开发的功能。 玩,Dropwizard和Spring Boot都显得有吸引力。 我会愿意使用上述任何一种,但是我一直无法得到一个简单的“保存文件,重新加载网页”的工作流与任何上述设置。 这怎么能做到呢?