小编Mon*_*key的帖子

如何在Spring Boot应用程序中使用配置(properties/yml)文件中的属性?

如何在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框架的新手(但不是一般的编程).

我已阅读过这些页面,但没有完整的示例,只有片段:

[1] http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html

[2] https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

java groovy spring spring-4

4
推荐指数
2
解决办法
9437
查看次数

如何找到所有没有 strict_types 声明的 php 类文件(RegExp / PhpStorm)

我试图将严格的类型声明添加declare(strict_types=1);到特定目录下的所有 PHP 类和特征文件。

  1. 如何使用 Linux 终端获取没有该声明的文件列表?

  2. 如何使用 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)

注释和导入(“使用”)在类文件中是可选的。

我做了什么:

  • 试图找到一个 PhpStorm 检查来完成我想要的
  • 尝试正则表达式,但没有找到任何在多行上下文中搜索缺少内容的语句

php regex regex-negation phpstorm

1
推荐指数
1
解决办法
1058
查看次数

标签 统计

groovy ×1

java ×1

php ×1

phpstorm ×1

regex ×1

regex-negation ×1

spring ×1

spring-4 ×1