我Bean在用@Configuration修饰的类中定义了:
@Configuration
public class MyBeanConfig {
@Bean
public String configPath() {
return "../production/environment/path";
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个用@TestConfiguration修饰的类应该覆盖它Bean:
@TestConfiguration
public class MyTestConfiguration {
@Bean
@Primary
public String configPath() {
return "/test/environment/path";
}
}
Run Code Online (Sandbox Code Playgroud)
该configPathbean用于设置外部文件的路径,该文件包含必须在启动期间读取的注册码.它用在@Component类中:
@Component
public class MyParsingComponent {
private String CONFIG_PATH;
@Autowired
public void setCONFIG_PATH(String configPath) {
this.CONFIG_PATH = configPath;
}
}
Run Code Online (Sandbox Code Playgroud)
在尝试调试时,我在每个方法中设置了一个断点以及测试配置类的构造函数.在@TestConfiguration类的构造函数断点命中,所以我知道我的测试配置类实例化,但是configPath()该类的方法不会被击中.相反,configPath()正常的@Configuration类的方法被命中,而@Autowired Stringin MyParsingComponent总是../production/environment/path而不是预期的/test/environment/path.
不知道为什么会这样.任何想法将不胜感激.
我正在构建购物车,并且使用了购物车服务,在该服务中,我将数量分配给产品/将产品添加到购物车。除了使用take获取可观察项$的第一个实例外,还有其他方法吗?
我正确导入了take运算符,但它始终给我运行时错误。如果我不使用take,那么分配的数量是一些随机整数而不是1。
我在以下代码中的可观察值上使用take()时遇到以下错误:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Product } from '../app/models/product';
import 'rxjs/add/operator/take';//tried this one too
import { take } from 'rxjs-compat/operator/take';
@Injectable({
providedIn: 'root'
})
export class ShoppingCartService {
constructor(private db: AngularFireDatabase) { }
private create() {
return this.db.list('/shopping-carts').push({
dateCreated: new Date().getTime()
});
}
private getCart(cartId: string) {
return this.db.object('/shopping-carts/' + cartId);
}
private async getOrCreateCartId() {
let cartId = localStorage.getItem('cartId');
if (cartId) return cartId;
let result = await …Run Code Online (Sandbox Code Playgroud) 我有两节课。当我将类 TapeDeckTestDrive 放在文本编辑器上时,它运行良好。当我把 TestDrive 类放在第一位时,它给出了找不到主类的错误。为什么是这样?
class TapeDeck {
boolean canRecord = false;
void playTape(){
System.out.println("tape playing");
}
void recordTape(){
System.out.println("tape recording");
}
}
class TapeDeckcTestDrive{
public static void main(String[] args){
TapeDeck t = new TapeDeck();
t.canRecord = true;
t.playTape();
if (t.canRecord == true) {
t.recordTape();
}
}
}
Run Code Online (Sandbox Code Playgroud)
此格式错误
VS
以下工作正常:
class TapeDeckcTestDrive{
public static void main(String[] args){
TapeDeck t = new TapeDeck();
t.canRecord = true;
t.playTape();
if (t.canRecord == true) {
t.recordTape();
}
}
}
class TapeDeck {
boolean …Run Code Online (Sandbox Code Playgroud) 我实例化了两个Observable对象:
const observable1 = new Observable.create(observer => observer.next(1));
const observable2 = new Observable.create(observer => observer.next(2));
Observable.forkJoin([observable1, observable2]).subscribe(res => console.log(res));
Run Code Online (Sandbox Code Playgroud)
forkJoin()即使每个observable.subscribe()都在工作,以上内容也不起作用。
有什么想法吗?
谢谢
angular ×2
java ×2
angularfire2 ×1
ionic2 ×1
methods ×1
rxjs ×1
spring-boot ×1
spring-test ×1
take ×1
typescript ×1