【问题标题】:Error at compilation by Maven of the Spring Petclinic projectSpring Petclinic 项目的 Maven 编译时出错
【发布时间】:2014-01-31 21:37:19
【问题描述】:

我从https://github.com/spring-projects/spring-petclinic/下载了Spring Petclinic项目

Eclipse 编译工作正常——我可以从 Tomcat 运行项目。但是在使用相同 JDK jdk1.6.0_45 进行 maven 编译时出现错误:

org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder 必需:java.lang.Object。完整的错误如下:

[错误] 编译错误:[信息] -------------------------------------------------- ----------- [错误] /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:

不兼容的类型;推断类型参数 java.lang.Object 不 符合找到的类型变量 B 的边界: org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder 必需:java.lang.Object

使用调试输出运行一开始出现以下错误:

SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。

SLF4J:默认为无操作 (NOP) 记录器实现

SLF4J:请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder 更多细节。

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

【问题讨论】:

  • 这是一个奇怪的错误。您是否尝试过在打开调试输出的情况下运行 (-X)?结果如何?
  • 请看更正的描述
  • slf 的东西是正常的。能发一下日志吗?

标签: java eclipse spring maven


【解决方案1】:

根据评论,我在 pom.xml 中更改了 Spring 版本,指向 4.0.1。而不是 4.0.0。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-21
    • 2014-12-21
    • 2018-07-10
    • 2018-03-20
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多