Tag: 春天开机

以编程方式重新启动Spring Boot应用程序/刷新Spring上下文

我试图以编程方式重新启动我的Spring应用程序,而无需用户介入。 基本上,我有一个页面,允许切换应用程序的模式(实际上意味着切换当前活动的配置文件),据我所知我必须重新启动上下文。 目前我的代码非常简单,只是重启位(顺便说一下,这是Kotlin): context.close() application.setEnvironment(context.environment) ClassUtils.overrideThreadContextClassLoader(application.javaClass.classLoader) context = application.run(*argsArray) 然而,我做context.close()的时候立即存在JVM。 我也尝试了context.refresh()但似乎只是简单地杀死Tomcat / Jetty(尝试两个,以防万一它是一个Tomcat的问题),然后没有任何反应。 我也看到以编程方式重新启动Spring Boot应用程序,但从这些答案似乎没有任何工作。 此外,我看了一下据说具有/restart端点的弹簧执行器,但这似乎不再存在? 帮助将不胜感激。 谢谢。

正确的方法为不可变的构造函数注入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属性是不可变的。

在@Service中使用Kotlin的Spring Boot @Autowired始终为空

目前我尝试用Kotlin重写我的Java Spring Boot应用程序。 我遇到了一个问题,即在所有使用@Service注释的类中,依赖注入都无法正常工作(所有实例均为null )。 这里是一个例子: @Service @Transactional open class UserServiceController @Autowired constructor(val dsl: DSLContext, val teamService: TeamService) { //dsl and teamService are null in all methods } 在Java中做同样的工作没有任何问题: @Service @Transactional public class UserServiceController { private DSLContext dsl; private TeamService teamService; @Autowired public UserServiceController(DSLContext dsl, TeamService teamService) { this.dsl = dsl; this.teamService = teamService; } […]