小编k-d*_*den的帖子

Spring依赖注入Spring TestExecutionListeners无法正常工作

如何在我编写的扩展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 …

java spring-test

8
推荐指数
1
解决办法
768
查看次数

在新标签中打开:'Bing'如何做到这一点?(IE9)

target ="_blank"在新选项卡或新窗口中打开链接基于用户设置,当我单击target ="_blank"链接时,它将在新窗口中打开(IE9).但是在Bing中,当点击"查看完整尺寸图像"时,它会在新标签页中打开!(你现在可以测试一下)

他们是怎么做到的?

html javascript html5 bing internet-explorer-9

7
推荐指数
1
解决办法
1976
查看次数

使用Jersey 2和Spring Boot向Annotation驱动的swagger.json添加授权

我正在尝试将基本身份验证添加到Swagger UI,以获得使用Spring Boot构建的Swagger-annotated Jersey 2.0 Web服务.我正在使用:

  • Spring Boot 1.5.4
  • 弹簧引导起动球衣
  • Swagger UI 3.0.4
  • (Maven包)swagger-jersey2-jaxrs 1.5.13

我能够在我的资源上使用以下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)

jersey swagger swagger-ui spring-boot

4
推荐指数
1
解决办法
2172
查看次数