简体   繁体   中英

Error at compilation by Maven of the Spring Petclinic project

I downloaded the Spring Petclinic project from https://github.com/spring-projects/spring-petclinic/

The Eclipse compilation works fine – I could run the project from Tomcat. However at maven compilation with the same JDK jdk1.6.0_45 got the error:

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

Running with debug output got the following error in the very beginning:

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.

The code for the VisitsViewTests is as follows:

@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")));
}
}

Based on the comment I changed the Spring version in the pom.xml, pointing to 4.0.1. instead of 4.0.0.

<spring-framework.version>4.0.1.RELEASE</spring-framework.version>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM