在我的 Spring Boot 测试中,我使用了 2 个具有不同限定符的模拟 bean:
@RunWith(SpringRunner.class)
@SpringBootTest
class HohoTest {
@MockBean @Qualifier("haha") IHaha ahaha;
@MockBean @Qualifier("hoho") IHaha ohoho;
}
Run Code Online (Sandbox Code Playgroud)
由于我没有明确使用这些 bean,我宁愿将它们从类主体中移开,因为@MockBean注释现在是可重复的:
@RunWith(SpringRunner.class)
@SpringBootTest
@MockBean(IHaha.class)
@MockBean(IHaha.class)
class HohoTest {}
Run Code Online (Sandbox Code Playgroud)
但是,我还需要传入一个限定符,因为它们具有相同的类型。关于如何实现这一目标的任何想法?
当我创建 ELB(即应用程序负载均衡器)时,Amazon 为其提供一个 DNS 名称,例如:
myalb-1472119708.eu-central-1.elb.amazonaws.com
现在,我想终止我的 ALB 上的 TLS/SSL,但是,我不想附加我自己的证书(例如来自证书管理器的证书),我可以通过默认 DNS 名称(ALB 的)访问我的应用程序)通过 HTTPS:
https://myalb-1472119708.eu-central-1.elb.amazonaws.com
但是,使用默认配置,我只能通过 HTTP 访问我的应用程序:
http://myalb-1472119708.eu-central-1.elb.amazonaws.com
AWS 支持这个(反问句)吗?有计划在不久的将来添加此功能吗?谢谢。
更新:毕竟这不是一个很难实现的功能。此外,SSL 是当今运行(安全)Web 应用程序的事实上的标准。我相信,AWS可以为每个区域的ELB颁发通配符证书,例如:
*.eu-central-1.elb.amazonaws.com
然后默认将其附加到每个 ALB。或者发布每个区域的证书 ARN 列表。这将使开发人员无需为非生产项目付出额外的努力(购买域名、在 ACM 中注册证书)。
ssl amazon-web-services amazon-elb tls1.2 aws-application-load-balancer
我有一个在 Google Domains 中注册的域,并使用 AWS Route 53 作为 NS。\n该域有多个子域(一些用于我们的应用程序,一些用于我们的公共网站)
\n*.dev.mydomain.com(指向我们开发应用程序的云前端的\'A\'记录)效果很好,\n*.app.mydomain.com(指向我们实时应用程序的云前端的\'A\'记录) )效果很好
\nwww.mydomain.com(指向 Bluehost 上托管我们的 Wordpress 网站的 IP 地址的“A”记录)效果很好
\n我不明白的是如何让 mydomain.com(没有任何子域)指向与 www 相同的 Bluehost WordPress 站点。\n我配置了:
\n*.mydomain.com(指向同一bluehost IP的\'A\'记录)
\n但我得到的是:
\n\n\n无法访问此站点\xe2\x80\x99\n找不到
\n
mydomain.com\xe2\x80\x99s 服务器 IP 地址。DNS_PROBE_FINISHED_NXDOMAIN
我有一个名为Parent的组件,其中有另一个名为Child 的组件:
<Parent>
<Child/>
</Parent>
Run Code Online (Sandbox Code Playgroud)
所以生命周期如下:
我可以在第 2 步之后和第 3 步之前以某种方式进行额外的父初始化吗?
更新:
<Parent>
<Child/>
</Parent>
Run Code Online (Sandbox Code Playgroud)
class ThirdPartyLib {
init(elementId) {
console.log(`initializing element: ${elementId}`);
// element with #id: elementId should exist!
// document.getElementById(elementId).style.color = "red";
}
}
class Parent extends React.Component {
constructor(props) {
super(props);
console.log("Parent's constructor");
}
render() {
console.log("rendering Parent");
new ThirdPartyLib().init("parent");
return (
<div id="parent">Parent: {this.props.name}
<Child name="Sara"/>
</div>
);
}
componentDidMount() {
console.log("Parent is mounted");
}
} …Run Code Online (Sandbox Code Playgroud)假设我有几个实现单个接口的Spring组件:
interface Haha
@Component class HahaImpl1: Haha {
@Autowired lateinit var repo: JpaRepository<Data, Long>
}
@Component class HahaImpl2: Haha
@Service
class Yoyo {
@Autowired lateinit var haha: Haha
}
Run Code Online (Sandbox Code Playgroud)
如何将正确的依赖项注入我Yoyo可以在application.properties文件内部指定的服务中?
myApp.haha=impl1
Run Code Online (Sandbox Code Playgroud)
我可以创建一个配置,但是随后我将不得不删除@Component我不想要的注释,因为在Haha实现类中,我将注入其他bean(服务,控制器等):
@Configuration
class MyConfiguration {
@Bean
@ConditionalOnProperty(name = ["myApp.haha"], havingValue = "impl1", matchIfMissing = true)
fun config1(): Haha = HahaImpl1()
@Bean
@ConditionalOnProperty(name = ["myApp.haha"], havingValue = "impl2")
fun config2(): Haha = HahaImpl2()
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢。
在我的反应式 REST API 中,我试图返回一个XML响应。但是,我总是得到一个JSON,即406 NOT_ACCEPTABLE。知道为什么吗?
@RestController
@RequestMapping(path = "/xml", produces = APPLICATION_XML_VALUE)
public class RestApi {
@GetMapping(path = "/get")
public Publisher<ResponseEntity> get() {
return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(new Datta("test")));
}
@PostMapping(path = "/post", consumes = APPLICATION_XML_VALUE)
public Publisher<ResponseEntity<Datta>> post(@RequestBody Datta datus) {
datus.setTitle(datus.getTitle() + "!");
return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(datus));
}
}
Run Code Online (Sandbox Code Playgroud)
java.lang.AssertionError: 预期:application/xml 实际:application/json;charset=UTF-8
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id "io.spring.dependency-management" version "1.0.7.RELEASE"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.8"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Run Code Online (Sandbox Code Playgroud)
java ×3
spring-boot ×3
amazon-elb ×1
autowired ×1
aws-application-load-balancer ×1
bluehost ×1
kotlin ×1
nameservers ×1
reactjs ×1
spring-bean ×1
spring-test ×1
ssl ×1
tls1.2 ×1
xml ×1