Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法自动连接webApplicationContext Spring MVC测试_Java_Spring_Mockito_Spring Mvc Test - Fatal编程技术网

Java 无法自动连接webApplicationContext Spring MVC测试

Java 无法自动连接webApplicationContext Spring MVC测试,java,spring,mockito,spring-mvc-test,Java,Spring,Mockito,Spring Mvc Test,我有一个用SpringFramework 3.2.4创建的RESTAPI。我试图在WebApplicationContext中编写测试用例。我从服务器日志中看到,xml配置文件已加载,但在执行TestContextManager时失败 ROR org.springframework.test.context.TestContextManager- Caught exception while allowing TestExecutionListener [org.springframework.

我有一个用SpringFramework 3.2.4创建的RESTAPI。我试图在WebApplicationContext中编写测试用例。我从服务器日志中看到,xml配置文件已加载,但在执行TestContextManager时失败

ROR org.springframework.test.context.TestContextManager- Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@4c980278] to prepare test instance
这是我的测试课:

@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
   @ContextConfiguration(locations = {"file:WebContent/WEB-INF/applicationContext.xml","file:WebContent/WEB-INF/spring-security.xml","file:WebContent/WEB-INF/spring-servlet.xml"})


public class AppControllerTest {

private MockMvc mockMvc;

@Autowired
private WebApplicationContext webApplicationContext;


@Before
public void setUp() {
    //Mockito.reset();//awesome_service
    mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
}


@Test
public void testGetSignupForm() throws Exception {
    this.mockMvc.perform(get("/apps"))
            .andExpect(status().isOk());
}
}

这是我的控制器

@Controller
@RequestMapping(value = "/apps")

public class AppController
{
@Resource(name = "appAPIService")
private AppAPIService appAPIService;

@Resource(name = "applicationVersionService")
private ApplicationVersionService applicationVersionService;

@Resource(name = "applicationService")
private ApplicationService applicationService;

@Autowired
Validator validator;

private static final Logger LOGGER = LoggerFactory.getLogger(AppController.class);

@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(Model.class, "model", new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) {
            BasicDBObject obj = (BasicDBObject)JSON.parse(text);

            Model model = new Model();
            model.setPrice(obj.getInt(ApplicationFields.MODEL_PRICE,0));
            model.setTrial(obj.getInt(ApplicationFields.MODEL_TRIAL,0));
            model.setType(obj.getString(ApplicationFields.MODEL_TYPE));

            setValue(model);
        }
    });
}

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<String> find(HttpServletRequest request, @RequestParam(value="query", required=false) String queryString, @RequestParam(value="sort", required=false) String sortString, @RequestParam(value="pageNumber", required=false) Integer pageNumber, @RequestParam(value="limit", required=false) Integer limit, @RequestParam(value="userId", required=false) String hostUserId)
{
    ObjectId marketplaceId = null;
    try
    {   
        marketplaceId = AuthenticationUtils.getUserId();

        BasicDBObject query;
        try
        {
            query = FormatUtils.toJsonObject(queryString);
        }
        catch(Exception e)
        {
            return ResponseUtils.badRequest("query", "Invalid query: " + queryString);
        }

        BasicDBObject sort;
        try
        {
            sort = FormatUtils.toJsonObject(sortString);
        }
        catch(Exception e)
        {
            return ResponseUtils.badRequest("sort", "Invalid sort: " + sortString);
        }

        return appAPIService.find(marketplaceId, query, sort, pageNumber, limit, hostUserId);
    }
    catch (Exception e)
    {
        String message = "Unable to find apps";
        ToStringBuilder builder = new ToStringBuilder(message);
        LoggingUtils.addToBuilder(builder, request);
        builder.append("marketplaceId", AuthenticationUtils.getUserId());

        LOGGER.error(builder.toString(), e);            
        return ResponseUtils.internalError();           
    }
}


}

applicationContext.xml、spring-security.xml和spring-servlet.xml都在WebContent/WEB-INF中。。。。它们相当大,所以我没有把它们包括在这里。帮助任何人??您需要向我们展示DependencyInjectionTestExecutionListener.class的代码,因为这就是故障所在。