将 Groovy bean 定义放在 Spring Boot webapp 中的什么位置? [英] Where to put Groovy bean definitions in a Spring Boot webapp?

查看:47
本文介绍了将 Groovy bean 定义放在 Spring Boot webapp 中的什么位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Spring Boot 我可以用我的 web 应用程序创建一个 jar(允许我根据需要将它作为 java -jar test-0.1.0.jar 执行).我想使用 groovy bean def 语法配置 Spring bean,使用一个单独的文件,如 beans.groovy 将包含定义.

Using Spring Boot I can get a jar created with my webapp (allowing me to execute it as java -jar test-0.1.0.jar as I want). I would like to configure the Spring beans using the groovy bean def syntax, with a separate file like beans.groovy that would contain the definitions.

我怎样才能在我的 jar 中包含那个 groovy 文件,我怎样才能告诉 Spring 加载它?

How can I have that groovy file included in my jar and how can I tell Spring to load it?

我在网上看到了一些例子,展示了如何以这种方式与 spring boot 一起定义 bean,但没有解释如何将那个 groovy 文件包含在 jar 中并作为 web 应用程序运行.

I've seen a few examples around the web showing how to define beans this way together with spring boot, but none explain how to get that groovy file included in the jar and run as a webapp.

推荐答案

SpringApplication 接受 Resource 路径作为源,所以只包含一个 String以.groovy"结尾,例如

SpringApplication accepts Resource paths as sources, so just include a String ending in ".groovy", e.g.

public static main(String args[]) {
    SpringApplication.run("classpath:beans.groovy", args);
}

这篇关于将 Groovy bean 定义放在 Spring Boot webapp 中的什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆