Fitnesse Integration with Spring MVC に問題があります。
テストする私のユースケースは認証です:
spring Context をロードする一般的な Fixture があります。
public abstract class GenericSpringFixture extends GenericBelFixture {
protected static AutowireCapableBeanFactory beanFactory;
protected static ClassPathXmlApplicationContext context;
static {
initSpring();
}
public static void initSpring() {
if ((context == null) || !context.isActive()) {
context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-fitnesse-common.xml");
beanFactory = context.getAutowireCapableBeanFactory();
}
}
public GenericSpringFixture() {
beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
}
public static AutowireCapableBeanFactory returnBeanFactory() {
return beanFactory;
}
}
applicationContext-fitnesse-common.xml ファイルは、My プレートフォームのすべての依存関係をロードしています。これには、私の servlet(Spring Mvc Files) config が含まれます。
私のフィクスチャコードは次のとおりです。
public class IdentificationUtilisateur extends GenericSpringFixture{
@Autowired
private WebApplicationContext webApplicationContext;
@Autowired
private FilterChainProxy springSecurityFilterChain;
private MockMvc mockMvc;
public void seLogerAvecIdentifiantEtMotDePasse(String identifiant,
String motDePasse) {
this.mockMvc = MockMvcBuilders
.webAppContextSetup(this.webApplicationContext)
.addFilters(this.springSecurityFilterChain).build();
}
public void accesReussi() throws Exception{
mockMvc.perform(
post("/j_spring_security_check")
.param("j_username", "bilal")
.param("j_password", "Pa1234567"));
}
}
問題は、Spring が webApplicationContext を見つけることができないことです。
org.springframework.beans.factory.BeanCreationException: 「ma.awb.ebk.bel.web.fixture.authentication.IdentificationUtilisateur」という名前の Bean を作成中にエラーが発生しました: 自動配線された依存関係の注入に失敗しました。ネストされた例外は org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.context.WebApplicationContext ma.awb.ebk.bel.web.fixture.authentication.IdentificationUtilisateur.webApplicationContext; です。ネストされた例外は org.springframework.beans.factory.NoSuchBeanDefinitionException です: タイプ [org.springframework.web.context.WebApplicationContext] の適格な Bean が依存関係で見つかりません: この依存関係のオートワイヤー候補として適格な少なくとも 1 つの Bean が必要です。依存関係アノテーション: {@org.springframework.beans.factory.annotation.
My Slim フィクスチャとテスト Spring mvc の唯一の違いは、テスト MVC では、junit コンテキスト上にあり、Junit テストでこの注釈が有効になっていることです。
@WebAppConfiguration
ご協力いただきありがとうございます 。