0

私はSpring Boot 1.4を使用していますが、

統合テストに @SpringBootTest アノテーションを使用すると、null ポインターが返されます。

@RunWith(SpringRunner.class);
@SpringBootTest
public class MyControllerTest {
  @Test
  public void mytest {
     when().
            get("/hello").
     then().
            body("hello");
  }
}

メインクラスの場合:

@SpringApplication
@EnableCaching
@EnableAsync
public class HelloApp extends AsyncConfigureSupport {
  public static void main(String[] args) {
     SpringApplication.run(HelloApp.class, args);
  }

  @Override
  public Executor getAsyncExecutor() {
    ...
  }
}

次に、私のコントローラーで:

@RestController
public class HelloController {
  @Autowired
  private HelloService helloService;

  @RequestMapping("/hello");
  public String hello() {
    return helloService.sayHello();
  }
}

ハローサービス

@Service
public class HelloService {
  public String sayHello() {
    return "hello";
  }
}

しかし、リクエストを処理するときに helloService の場合は NullPointException と言う方法があります。

私は何が欠けていますか?

4

2 に答える 2