Tag: 春天

尝试在Kotlin和Spring引导下使用JPA时出现BeanDefinitionParsingException

当我尝试使用springboot + JPA + kotlin + maven时,我得到这个异常 org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Bean method 'init' must not be private or final; change the method's modifiers to continue Offending resource: com.wirecard.kotlin.jpa.Application at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) at org.springframework.context.annotation.BeanMethod.validate(BeanMethod.java:50) at org.springframework.context.annotation.ConfigurationClass.validate(ConfigurationClass.java:219) at org.springframework.context.annotation.ConfigurationClassParser.validate(ConfigurationClassParser.java:528) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:307) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at […]

带kotlin功能路由器的非反应性Spring Web

我可以使用新的Kotlin DSL来设置路由,例如: router { ("/blog" and accept(TEXT_HTML)).nest { GET("/", fooHandler::findAllView) GET("/{slug}", fooHandler::findOneView) } ("/api/blog" and accept(APPLICATION_JSON)).nest { GET("/", barHandler::findAll) GET("/{id}", barHandler::findOne) } } 与无反应的网页部分? 基础数据库将是Postgres和非Reactive基于servlet的应用程序服务器,因此我不希望/不需要使用Flux或Mono作为barHandler或存储库函数的返回类型。 但是我喜欢新的路由器DSL和Kotlin一起使用,它比基于@RequestMapping注解更强大,并且更容易掌握所有的应用路由。

Kotlin + SpringBoot 2.0.0-M4失败tu加载应用程序上下文(BeanCreationException)

我正在与Kotlin和Spring(通过SpringBoot)合作。 我在2.0.0-M3,一切正常。 我决定跳到M4。 然后,我有一些麻烦。 我得到了以下堆栈跟踪: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at […]

我不能在Springboot-Kotlin中排除MongoAutoConfiguration(MongoSocketOpenException)

当试图排除MongoAutoConfiguration时,我得到一个MongoSocketOpenException。 我试图连接到一个远程的MongoDB。 考虑到我在Kotlin工作,@EnableAutoConfiguration语法是否正确? 例外: com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongo-java-driver-3.4.2.jar:na] at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongo-java-driver-3.4.2. jar:na] at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongo-java- driver-3.4.2.jar:na] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_20] Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_20] at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_20] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) ~[na:1.8.0_20] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_20] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_20] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_20] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_20] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_20] at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) […]

在Kotlin项目中使用@Value注释时出现编译器警告

有没有Kotlin语言的任何类型,我可以用在后期初始化而不是java.lang.Integer所以我没有得到一个编译器的警告? 假设我有这样一个班级: class SomeClass { @Value(#{config['poolCapacity']?:'5000'}) lateinit var somePool: Integer } 我不能使用Kotlin的Int类型,因为它是原始类型, lazeint不接受它。 如果我坚持java.lang.Integer它工作得很好,但我得到这样的编译器警告: SomeClass.kt:(20,24):这个类不应该在Kotlin中使用。 改用kotlin.Int。 显然我可以自己创建需要的类型,但是我只是想知道是否有什么东西可以用,并建议我们在这种情况下使用,而我根本找不到它? (注释的构造函数在这种情况下不是解决方案)。

Reactive Spring 5安全性Kotlin的主要名称

我正在尝试将Reactive Spring Security示例( https://github.com/spring-tips/reactive-security/blob/master/src/main/java/com/example/securitydemo/SecurityDemoApplication.java )转换为Kotlin 。 这是我迄今为止: WebConfiguration.kt @Configuration class WebConfiguration { fun message(serverRequest: ServerRequest): Mono<ServerResponse> { val principalPublisher = serverRequest.principal().map { p -> "Hello, " + p.name + "!" } return ServerResponse.ok().body(principalPublisher.toMono()) } @Bean fun routes() = router { GET("/message") { ServerResponse.ok().body(message(it)) } } } SecurityConfiguration.kt @Configuration @EnableWebFluxSecurity class SecurityConfiguration { @Bean fun userDetailsRepository(): […]

Spring MVC错误404错误的请求Kotlin

我正在使用Kotlin开发Spring MVC应用程序。 我有一个简单的表单,当我提交时,我得到错误404错误的请求 。 我使用的Jetty服务器和Intellij社区版 。我试过调试,但因为我从来没有调试过的Web应用程序,它不是那么有用。 web.xml中 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>frontDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>frontDispatcher</servlet-name> <url-pattern>/springkotlinmvc/*</url-pattern> </servlet-mapping> </web-app> frontDispatcher-servlet.xml中 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:annotation-config/> <mvc:annotation-driven/> <context:component-scan base-package="org.manya.kotlin"/> <bean id="viewResolver" […]

正确的方法为不可变的构造函数注入Kotlin类

用Spring + Kotlin声明一个不可变构造函数注入类的正确方法是什么? 目前我有: @RestController public class AuthorizationController { @Inject lateinit var facebookAuth: FacebookAuthorizationService //Mutable? @RequestMapping("/authorization") public fun authorization(@RequestParam(value = "network-type", defaultValue = "Facebook") name: String, @RequestParam(value = "oauth-token") oauthToken: String, @RequestParam(value = "oauth-token-secret", required = false) oauthTokenSecret: String?): Authorization { //TODO: Handle other network types return facebookAuth.authorization(oauthToken) } } 我想facebookAuth属性是不可变的。

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

我用了 日食火星 jdk8 tomcat8 kotlin 1.0 即时处理java-> kotlin在春天项目 我在pom.xml中添加这个代码 <properties> <kotlin.version>1.0.0</kotlin.version> </properties> … <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> …. <build> <plugins> <plugin> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <additionalProjectnatures> <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> </additionalProjectnatures> <additionalBuildcommands> <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> </additionalBuildcommands> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerArgument>-Xlint:all</compilerArgument> <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <configuration> <mainClass>org.test.int1.Main</mainClass> […]

用Kotlin解释@Configuration @AutoConfigureAfter

我是一个python开发人员,对于Spring引导和gradle是全新的。 不过,我很好,与Java和Kotlin尽我所能。 我试图在本地主机上运行Spring Boot应用程序(Kotlin)。 除了这些行外,Gradle构建工作正常 @Configuration @AutoConfigureAfter(DispatcherServletAutoConfiguration::class) open class Assembly : WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter() { . . 没有值传递给参数resourceProperties,mvcProperties,beanFactory …. 我明白WebMvcAutoConfigurationAdapter构造函数期望这些参数,但不应该通过注释@Configuration和@AutoConfigureAfter自动传递。 由于我是春季引导全新的,我不知道什么是错的,在哪里。 由于这段代码已经在生产中运行,所以我很困惑我是否缺少一些本地配置或者gradle conf或其他东西。