如何在我编写的扩展AbstractTestExecutionListener的TestExecutionListener类中使用Spring依赖注入?
Spring DI似乎不适用于TestExecutionListener类.问题示例:
AbstractTestExecutionListener:
class SimpleClassTestListener extends AbstractTestExecutionListener {
@Autowired
protected String simplefield; // does not work simplefield = null
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
System.out.println("simplefield " + simplefield);
}
}
Run Code Online (Sandbox Code Playgroud)
配置文件:
@Configuration
@ComponentScan(basePackages = { "com.example*" })
class SimpleConfig {
@Bean
public String simpleField() {
return "simpleField";
}
}
Run Code Online (Sandbox Code Playgroud)
JUnit测试文件:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SimpleConfig.class })
@TestExecutionListeners(mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS, listeners = {
SimpleClassTestListener.class })
public class SimpleTest {
@Test
public void test(){
assertTrue();
}
}
Run Code Online (Sandbox Code Playgroud)
正如代码注释中所强调的那样,当我运行它时,它将打印"simplefield …
target ="_blank"在新选项卡或新窗口中打开链接基于用户设置,当我单击target ="_blank"链接时,它将在新窗口中打开(IE9).但是在Bing中,当点击"查看完整尺寸图像"时,它会在新标签页中打开!(你现在可以测试一下)
他们是怎么做到的?
我正在尝试将基本身份验证添加到Swagger UI,以获得使用Spring Boot构建的Swagger-annotated Jersey 2.0 Web服务.我正在使用:
我能够在我的资源上使用以下JerseyConfig和Swagger注释生成swagger.json文件. 这篇文章对于实现这一目标非常有帮助.
@Component
public class JerseyConfiguration extends ResourceConfig {
private static Log logger = LogFactory.getLog(JerseyConfiguration.class);
@Value("${spring.jersey.application-path:/}")
private String apiPath;
public JerseyConfiguration() {
registerEndpoints();
configureSwagger();
}
private void registerEndpoints() {
register(MyEndpoints.class);
// Generate Jersey WADL at /<Jersey's servlet path>/application.wadl
register(WadlResource.class);
// Lets us get to static content like swagger
property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "((/swagger/.*)|(.*\\.html))");
}
/**
* Configure the Swagger documentation for this API.
*/
private void configureSwagger() …Run Code Online (Sandbox Code Playgroud) bing ×1
html ×1
html5 ×1
java ×1
javascript ×1
jersey ×1
spring-boot ×1
spring-test ×1
swagger ×1
swagger-ui ×1