我想在使用spring @SpringBootTest时以与@ComponentScan相同的方式来排除某些软件包的扫描。 是否有类似的东西
@SpringBootTest(excludeFilters =@ComponentScan.Filter(
type = FilterType.REGEX,
pattern = "package\\.\\.to\\.Exclude.*"))
答案 0 :(得分:1)
似乎最好的解决方法是创建一个用@SpringBootApplication注释的类,并在那里配置扫描配置
public class Aggregator
{
private static readonly Object _lockObj = new Object();
public void Aggregate(Order order, Dictionary<OrderTypeEnum, Aggregate> aggregates)
{
lock (_lockObj)
{
aggregates[order.OrderType].Count++;
}
}
}
然后在单元测试中,您应该指定之前创建的测试类
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackageClasses ={TestConfiguration.class})
public class TestApp {
}