- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我上课了:
@WebServiceClient(name = "${service.name}", targetNamespace = "${service.namespace}", wsdlLocation = "${service.wsdlLocation}")
public class ExampleService extends Service {
@Value("${service.wsdlLocation}")
private static String wsdlLocation;
}
它是 mvn 项目的一部分,我从本地 Maven 存储库编译并使用它作为我的其他 spring-boot 应用程序的依赖项,该应用程序具有配置 yml:
service:
name: name
namespace: namespace
wsdlLocation: wsdlLocation
有没有办法让这个ExampleService类使用“父”项目的配置?
编辑:
出现了两个答案,但我觉得我没有问清楚。我现在想做的是在我的“父”项目中使用类 ExampleService 并使其看到该父项目的配置。到目前为止,例如我在父项目代码中编写如下内容:
ExampleService exampleService = new ExampleService();
System.out.println(exampleService.getWsdlLocation());
打印 Null。所以我正在寻找一些解决方案。
编辑2:这是我的类(class)。父项目:
package com.example.kris.parentservice;
import com.example.kris.childservice.ExampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/example")
public class ExampleController {
// @Autowired
private ExampleService exampleService;
@Value(value = "${service.wsdlLocation}")
private String wsdlLocation;
@GetMapping(value = "/example")
public void example() {
exampleService = new ExampleService();
System.out.println("ExampleService field: " + exampleService.getWsdlLocation());
System.out.println("@Value: " + wsdlLocation);
}
}
子项目:
package com.example.kris.childservice;
import org.springframework.beans.factory.annotation.Value;
public class ExampleService {
@Value("${service.wsdlLocation}")
private String wsdlLocation;
public String getWsdlLocation() {
return wsdlLocation;
}
}
运行父 Controller 后输出:
ExampleService field: null
@Value:test.wsdl.location
最佳答案
YamlPropertySourceLoader 在 Spring Boot 应用程序注入(inject)像这样的 bean 时很有帮助
@Bean
public PropertySource<?> yamlPropertySourceLoader() throws IOException {
YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
PropertySource<?> applicationYamlPropertySource = loader.load("application.yml",
new ClassPathResource("application.yml"), "default");
return applicationYamlPropertySource;
}
关于java - 从 yml 配置获取值到依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58318954/
我已经成功创建了我的第一个 django 项目。 我的项目 foo 和 foobar 中有两个应用程序。 我在每个应用程序文件夹中创建了一个名为“fixtures”的文件夹。我没有在我的setting
我遵循了 cap + nginx + unicorn 上的文档,但在理解如何正确进行数据库部署时遇到了一些问题。 /config/database.yml 不应该在 git repo 中(最好) 在/
GitLab server can't start .原因很可能是 gitlab.yml 配置文件不正确。 用什么工具检查yml语法是否正确? 我试过 Notepad++ 和 SublimeText,
我们有一个站点范围的 config.yml 文件,它联系 api key 等... 我的另一个 YML 文件能否访问 config.yml 中的值? 配置文件: development: th
我正在尝试在我的第一个测试应用程序中设置用户和安全管理,但我已经有点迷失了,不知道什么是做什么的。 到目前为止我的设置:Symfony 2.5、SonataUserBundle(以及 FOSUserB
我需要在 application.yml 中使用 yaml anchor 引用和字符串连接对于 Spring Boot 应用程序。动机是重用现有配置而不是复制它们。例如,我们有以下 applicati
我需要将单个 YML 文件拆分为多个 YML 文件: 微服务.yml: #------------------------------------------------------------- #
在我的 Symfony2 config.yml 文件中,我想导入一些我希望收集在单独的 yml 文件中的配置。 我用过: imports: - { resource: parameters.yml }
我是新的 docker 用户。在不同的手册中,我通常发现 docker-compose.yml 文件用于描述 docker 作业,但在 docker 站点上为此目标使用了 docker-stack.y
我不明白这两种在 Symfony2 中设置全局常量的方法之间的区别。是否只能在 config.yml (+configuration.php) 中设置默认值和类型? 最佳答案 参数.yml 文件是所有
在 config.yml 中,我看到了 monolog、web_profiler 等根元素。那些服务可以在 service.yml 中配置吗?换句话说,我在 service.yml 中定义的服务是否可
我阅读了这个文档:https://serverless.com/framework/docs/providers/google/guide/services/ users/ serverless.
我正在从事 CI/CD 项目(使用 circleci 管道),目前,我坚持让我的“create_infrastructure”工作正常工作。下面是作业 # AWS infrastructure
编辑:原始标题“文本环境:”平台“sqlite”不支持函数“year”” 将 beberlei\DoctrineExtensions 合并到测试环境中会产生 Uncaught PHP Exceptio
abc.yml: d_lab: 192.168.1.1 d_location: /ephemeral ema: apple: 10.0.0.1 orange: 10.0.0.2
我的 springboot 应用程序有一些 yml 文件(每个文件用于各种配置文件 - dev、prod)来加载配置。我正在将配置移至数据库。 示例配置如下: admin: id: user05
我有一个大型剧本,它使用多个角色来设置新服务器。我想重新使用剧本,但为了退役阶段而不是调用 role_name/tasks/main.yml 并有很多 when: 语句,我想要告诉 Ansible 调
使用 bookdown 创作文档时,我知道有四个选项可以放置配置选项: _bookdown.yml _output.yml 第一个 .Rmd 的 yaml header 文档 传递给 bookdown
我们希望将我们的 azure pipeline build .ymls 模块化。对于完整的应用程序构建,将包括不同组件的构建 .yml 到主 .yml 中,将它们全部构建在一起。对于单独的组件,我们将
假设我的网站上有一个简单的传统联系表单,我希望它在发送电子邮件时在开发环境中使用主题“Test: (subject_field value)”,在生产环境中使用“(subject_field_valu
我是一名优秀的程序员,十分优秀!