Tag: spring

Spring在kotlin中注入通用接口实现列表

免责声明:Kotlin新手,可能是一个容易解决的问题或误解的基础知识。 我正在试图注入一个特定的接口的Spring实现列表,在一个普通的Java类中,这很容易,就像这样: @Autowired List myClassList; 但是在Kotlin做以下给我一个错误 @Autowired lateinit private var myClassList: List<IMyClass> // No beans of ‘? extends IMyClass’ or ‘List<? extends IMyClass>’ types found 这样做: @Autowired lateinit private var myClassList: List<IMyClass> 使注入工作,但不允许我使用接口中定义的函数,该函数将通用对象作为输入 // Out-projected type ‘IMyClass’ prohibits the use of ‘public abstract fun myFunction(obj: T!): T! defined in com.path.IMyClass’ 那么我该如何解决呢? 用一些特定的syntac来重写Kotlin中的接口更容易吗?

如何在eclipse maven web项目中编译kotlin

我用了 日食火星 jdk8 tomcat8 kotlin 1.0 即时处理java-> kotlin在spring项目 我在pom.xml中添加这个代码 1.0.0 … org.jetbrains.kotlin kotlin-stdlib ${kotlin.version} …. maven-eclipse-plugin 2.9 org.springframework.ide.eclipse.core.springnature org.springframework.ide.eclipse.core.springbuilder true true org.apache.maven.plugins maven-compiler-plugin 2.5.1 1.6 1.6 -Xlint:all true true org.codehaus.mojo exec-maven-plugin 1.2.1 org.test.int1.Main org.jetbrains.kotlin kotlin-maven-plugin ${kotlin.version} compile process-sources compile src/main/kotlin test-compile process-test-sources test-compile src/test/kotlin 但是当tomcat启动或创建为war文件时,不要将.kt文件进行complile .kt和.java文件在同一个包中混合使用 顺便说一句,当你启动tomcat或创建war文件,.java文件被编译但.kt文件不是 因此在WEB-INF / classes目录中存在.class(是.java的结果)和.kt文件(不是编译的) 这张图片是WEB-INF / classes目录 类文件夹 如何编译.kt文件?

Spring Boot无法在IntelliJ中运行单个测试

最近开始发生,但我不确定是什么改变了。 当我从IntelliJ运行所有测试时,一切都很好。 而且gradle build也很好。 当我运行一个unit testing时,一切都很好。 当我运行一个Web集成测试时,它失败,因为一个配置类具有所有的空属性。 配置类看起来像(Kotlin): @Component @ConfigurationProperties(prefix = “api”) public open class ApiConfigImpl : ApiConfig { 一个测试看起来像: @RunWith(SpringJUnit4ClassRunner::class) @ContextConfiguration(classes = arrayOf(ApplicationAssembly::class), loader = SpringApplicationContextLoader::class) @WebIntegrationTest open class CandidateProfileControllerTest { @Inject lateinit var profileRepo: CandidateProfileRepository //etc a few more deps used to setup test data @Test open fun getById() { val greg = […]

spring的数据mongodb和kotlin

使用弹簧数据mongodb使用kotlin时,我遇到了一个问题。 当我尝试从mongodb读取对象时,我得到一个错误,抱怨说我的数据类没有默认的无参数构造函数。 我可以通过给我的数据类中的每个字段的值来解决这个问题,所以编译器会生成一个默认的无参数构造函数。 当然,我不是真的想这样做。 我知道有一个jacksonkotlin模块,它包含在我的maven文件中。 它适用于反序列化对象,我得到了HTTP,所以我知道spring拿起它。 但似乎spring的数据mongodb不使用jackson对象映射器? 有没有办法我可以在弹簧数据mongodb中使用jackson对象映射器或修复没有非参数构造函数的问题?

如何定义一个调用枚举实例的xml配置spring bean?

我有一个枚举(这是kotlin,但没关系,也可能是Java) enum class AnEnum { A_VALUE { override fun aMethod(arg: ArgClass): AClass { //… } }; abstract fun aMethod(arg: ArgClass): AClass } 我需要一个Spring xml bean中的bean,它是调用枚举值的“aMethod”的结果。 看来我不能以通常的方式使用“工厂方法” 我知道如何获得枚举值的bean,如果这有助于打破这个问题: A_VALUE 我不知道如何创建一个types为“AClass”的bean,这是在enum实例上调用带有参数的方法的结果。 我不是很熟悉spring,而且在bean定义之前,我使用了构造函数或静态方法。

防止回滚 – Spring Data,JUnit和Neo4J

我有spring的数据Neo4j连接起来,很好地工作。 我建立了几个unit testing,并在测试类上使用@Transactional注释。 测试运行,但他们写的数据总是回滚。 在日志中我可以看到: ] onodrivers.http.request.HttpRequest … request: {“statements”:[{“statement”:”UNWIND {rows} as row MATCH … 但是我想压制这个,我尝试过使用(在Kotlin中): @Test @Commit fun myDbTest() {…} 和 @Test @Rollback(false) fun myDbTest() {…} 但是注释被忽略? 我似乎有大多数相反的问题,在那里需要回滚,但它不工作:)在我的情况下,回滚完美的作品,我想关闭它。

如何使用Netty4ClientHttpRequestFactory为Spring AsyncRestTemplate设置代理?

当我使用SimpleRequestFactory和AsyncRestTemplate时,我可以轻松配置一个HTTP代理服务器。 我可以做(Kotlin示例代码): @Bean open fun asyncRestTemplate(): AsyncRestTemplate { val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(“127.0.0.1”, 8008)) val requestFactory = SimpleClientHttpRequestFactory().apply { this.setConnectTimeout(TimeUnit.SECONDS.toMillis(10).toInt()) this.setReadTimeout(TimeUnit.SECONDS.toMillis(10).toInt()) this.setProxy(proxy) this.setTaskExecutor(taskExecutor()) } return AsyncRestTemplate(requestFactory) } 或者我可以简单地设置相应的系统属性: -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8008 。 然而,在我从SimpleClientHttpRequestFactory切换到Netty4ClientHttpRequestFactory的那一刻,没有直接配置代理的明显方式,看起来这个客户端也不尊重系统属性。 val requestFactory = Netty4ClientHttpRequestFactory().apply { this.setConnectTimeout(TimeUnit.SECONDS.toMillis(10).toInt()) this.setReadTimeout(TimeUnit.SECONDS.toMillis(10).toInt()) //this.setProxy(proxy) //??? } 一旦我换了netty客户端,我不知道如何通过代理。 我对使用netty客户端的兴趣是我不仅要做异步请求,而且我希望这是非阻塞的。 我希望在这里不要做错误的假设。 有谁知道如何使用Netty4ClientHttpRequestFactory时使用代理服务器,也许知道我可以使用Spring支持的另一个非阻塞客户端?

在org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated找不到属性’run’

我正在使用Gradle的Spring Boot。 升级到以下内容: classpath(“org.springframework.boot:spring-boot-gradle-plugin:1.3.0.RC1”) 。 。 。 从1.2.7.RELEASE导致以下问题: * What went wrong: A problem occurred evaluating root project ‘vampr’. > Could not find property ‘run’ on org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated@12e13f2b. 如何解决这个问题? 构建文件: buildscript { ext.kotlin_version = ‘1.0.0-beta-1038’ repositories { maven { url “https://repo.spring.io/libs-milestone” } maven { url “https://repo.spring.io/libs-release” } mavenLocal() mavenCentral() } dependencies { classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” classpath(“org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE”) } […]

在SpringBoot中,Firebase连接在Linux上不起作用

我想要实现的是打开一个连接到我的firebase数据库,并获得一些我需要解析的数据。 我正在使用Spring Boot框架,firebase,kotlin和gradle的admin sdk。 在Windows 10上,它是像预期的那样工作,但是当我尝试在我的Linux服务器上运行.jar文件时,它不会得到任何数据或错误。 它被困在ValueEventListener中。 我有ufw安装,但禁用它或添加端口5228:5230(tcp / udp),没有解决问题。 val dataMinifiedRef = database.reference.child(“minifiedData”).child(“areas”) dataMinifiedRef.addListenerForSingleValueEvent(object : ValueEventListener { override fun onCancelled(error: DatabaseError?) { log.info(error!!.message) } override fun onDataChange(dataSnapshot: DataSnapshot) { log.info(“Got data”) } }) 编辑:这是我解析服务帐户。 val str = “{\n” + … “}\n” // convert String into InputStream val serviceAccount = ByteArrayInputStream(str.toByteArray()) val options = FirebaseOptions.Builder() […]

在@Transactional方法调用期间,初始化期间Bean属性不为null变为null

我遇到了一个问题,在调用@Transactional方法期间bean的属性变为null。 UserService是在@Configuration类中声明的一个bean userRepository和passwordService在初始化期间是非空的(afterPropertiesSet) 在调用registerUser( @Transactional )期间,这些属性将变为null 这些属性具有不可空的types 用户服务的相同实例/ bean已根据打印使用 删除@Transactional似乎解决了这个问题 添加或删除@EnableTransactionManagement似乎什么都不做 服务: open class UserService (val userRepository: UserRepository, val passwordService: PasswordService) : InitializingBean { override fun afterPropertiesSet() { println(“### this.afterPropertiesSet”) println(“### this: ” + this) println(“### userRepository: ” + userRepository) println(“### passwordService: ” + passwordService) } @Transactional fun registerUser(request: UserRegistrationRequest): User { println(“### this.registerUser”) println(“### […]