2016-08-29 9 views
1

キュウリでSpringブート1.4を使用する場合、@Autowired Beanは注入されません。Cucumber-JVMでのSpringブート1.4の問題

しかし、私はプレーンなJunitテストを使うと、正しく注入されます! 私はhereを見ましたが、私の問題は解決しません。

@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 
} 

編集: だけ明確にする、私は、ビューCucumber with Spring Boot 1.4: Dependencies not injected when using @SpringBootTest and @RunWith(SpringRunner.class) を行なったし、これは

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

didntの仕事

を注釈入れ、その後、私は

(答えのように)これらのアノテーションを置きます
@ContextConfiguration 
@SpringBootTest 

+0

のpom.xmlにスプリングブート1.4と[キュウリの可能性のある複製を

固定:@SpringBootTestと@RunWithを(使用する場合に注入されない依存関係SpringRunner.class)](@stackoverflow.com/questions/38836337/cucumber-with-spring-boot-1-4- dependencies-not-injected-when-using-springboott) –

+0

@JörnHorstmann私ははっきりとその答えは、私のために働いていないと言って言った。 –

答えて

1

<dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-spring</artifactId> 
      <version>${cucumber-junit.version}</version> 
      <scope>test</scope> 
</dependency> 
UsersStepsクラスの

@SpringBootTest 
    @ContextConfiguration(classes = {ServicesApplication.class}) 
    @TestPropertySource(locations = "classpath:test.properties") 
    public class UsersSteps 
+0

これは私の作品です。私のシーンは、そのキュウリ1.2.5、春のブート1.4.4であり、 "春のブート料理の本"の例を実行し、元の注釈を@SpringBootTestに変更します @ContextConfiguration(classes = {BookPubApplication.class、TestMockBeansConfig.class} ) – avatas

関連する問題