org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'modelController' defined in file [D:\sts-bundle\pivotal-tc-server-developer-3.0.0.RELEASE\base-instance\wtpwebapps\ZZZ\WEB-INF\classes\cn\tabris\demo\controller\ModelController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [cn.tabris.demo.controller.ModelController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/google/gson/Gson
上面的错误很长,但我们只要看关键部分
nested exception is java.lang.NoClassDefFoundError: com/google/gson/Gson
意思是找不到Gson这个类。
其实楼主已经在工程中导入jar包 如下图
注意到gson-1.7-1.jar是在参考库内。经同事指点,jar包必须统一放到gsonMaven Dependencies库中才行。
找到pom.xml文件,在里面加上下面的配置语句
<!-- gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.7.1</version>
</dependency>
gson-1.7.1.jar被包含到了Maven Dependencies中。整个工程恢复正常