Spring boot 黄瓜JVM的Spring Boot 1.4问题

Spring boot 黄瓜JVM的Spring Boot 1.4问题,spring-boot,cucumber-jvm,cucumber-junit,cucumber-java,Spring Boot,Cucumber Jvm,Cucumber Junit,Cucumber Java,将Spring boot 1.4与cucumber一起使用时,不会注入@Autowired bean 但是当我使用普通Junit测试时,它们是正确注入的! 我已经看过了,但它不能解决我的问题 @SpringBootApplication @EnableSwagger2 @ComponentScan("org.services") public class ServicesApplication { public static void main(String[] args) {

将Spring boot 1.4与cucumber一起使用时,不会注入@Autowired bean

但是当我使用普通Junit测试时,它们是正确注入的! 我已经看过了,但它不能解决我的问题

@SpringBootApplication
@EnableSwagger2
@ComponentScan("org.services")
public class ServicesApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServicesApplication.class, args);
    }
}


@RunWith(Cucumber.class)
public class UsersTest {

}

@RunWith(SpringRunner.class)
@SpringBootTest
public class UsersSteps {

    @Autowired
    private UsersService _target;//null
}
编辑: 我只是想澄清一下,我确实有这个观点 然后把这个

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
没用

然后我将这些注释(如答案中所示)

也不起作用

修复

在pom.xml中

 <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>${cucumber-junit.version}</version>
            <scope>test</scope>
</dependency>

可能重复的@Jörn Horstmann我清楚地提到了上述问题,说答案对我不起作用。这对我起作用。我的场景是cucumber 1.2.5,spring boot 1.4.4,并运行“spring boot cookbook”一书中的示例,将原始注释更改为@SpringBootTest@ContextConfiguration(class={BookPubApplication.class,TestMockBeansConfig.class})
 <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>${cucumber-junit.version}</version>
            <scope>test</scope>
</dependency>
    @SpringBootTest
    @ContextConfiguration(classes = {ServicesApplication.class})
    @TestPropertySource(locations = "classpath:test.properties")
    public class UsersSteps