如何在Spring应用程序中使用外部配置?
package hello.example2.Container
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.client.RestTemplate
@RestController
class ContainerController {
@RequestMapping("/container/{cid}")
public list(@PathVariable Integer cid) {
def template = new RestTemplate();
def container = template.getForObject("http://localhost:5050/container/" + cid.toString(), Container);
return container;
}
}
Run Code Online (Sandbox Code Playgroud)
我想用配置选项(fe application.yml或application.properties)替换" http:// localhost:5050 ".
这是我的应用程序文件(Groovy):
package hello.example2
import groovy.transform.CompileStatic
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.Configuration
@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@CompileStatic
class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图设置"@Configuration"和"@EnableAutoConfiguration"但说实话我不知道他们在做什么.我是Java/Groovy和Spring框架的新手(但不是一般的编程).
我已阅读过这些页面,但没有完整的示例,只有片段:
[2] https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
我试图将严格的类型声明添加declare(strict_types=1);到特定目录下的所有 PHP 类和特征文件。
如何使用 Linux 终端获取没有该声明的文件列表?
如何使用 PhpStorm 添加缺失的声明(检查、替换路径 + 正则表达式)?
不带声明的示例 /src/Foobar.php:
<?php
/**
* class file
*/
namespace Foo\Bar;
use Other\Foo\Bar;
class Foobar {
// ..
}
Run Code Online (Sandbox Code Playgroud)
带有声明的示例 /src/Foobar.php:
<?php
/**
* class file
*/
declare(strict_types = 1);
namespace Foo\Bar;
use Other\Foo\Bar;
class Foobar {
// ..
}
Run Code Online (Sandbox Code Playgroud)
注释和导入(“使用”)在类文件中是可选的。
我做了什么: