Spring Petclinic项目Maven编译时出现java错误
我从https://github.com/spring-projects/spring-petclinic/下载了Spring Petclinic项目
Eclipse编译工作正常——我可以从Tomcat运行该项目。然而,在maven编译中使用相同的JDK jdk1。6.0_45出现错误:
org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder required: java.lang.Object. The full error is as follows:
[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /spring-petclinic/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java:[58,58] \spring-petclinic\src\test\java\org\springframework\samples\petclinic\web\VisitsViewTests.java:58:
incompatible types; inferred type argument(s) java.lang.Object do not conform to bounds of type variable(s) B found : org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder required: java.lang.Object
使用调试输出运行一开始就出现以下错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
VisitsViewTests的代码如下:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("VisitsViewTests-config.xml")
@ActiveProfiles("jdbc")
public class VisitsViewTests {
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
}
@Test
public void getVisitsXml() throws Exception {
ResultActions actions = this.mockMvc.perform(get("/vets.xml").accept(MediaType.APPLICATION_XML));
actions.andDo(print()); // action is logged into the console
actions.andExpect(status().isOk());
actions.andExpect(content().contentType("application/xml"));
actions.andExpect(xpath("/vets/vetList[id=1] /firstName").string(containsString("James")));
}
}
# 1 楼答案
根据评论,我在pom中更改了Spring版本。xml,指向4.0.1。而不是4.0.0