我正在使用templateRest将User对象发布到Rest Server但我遇到了以下错误:
Exception in thread “main” java.lang.NoClassDefFoundError:
com/fasterxml/jackson/core/JsonProcessingException at
edu.java.spring.service.client.RestClientTest.main(RestClientTest.java:33)
Caused by: java.lang.ClassNotFoundException:
com.fasterxml.jackson.core.JsonProcessingException at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) … 1 more
这是RestClientTest.java文件
public class RestClientTest {
public static void main(String[] args) throws IOException{
RestTemplate rt = new RestTemplate();
// System.out.println("Rest Response" + loadUser("quypham"));
// URL url = new URL("http://localhost:8080/rest/user/create");
rt.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
rt.getMessageConverters().add(new StringHttpMessageConverter());
// Map
这是UserRestServiceController.java文件
@Controller
public class UserRestServiceController {
@Autowired
public UserDao userDao;
@RequestMapping(value = "/rest/user/create",method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void addUser(@RequestBody User user){
userDao.save(user);
}
这是文件pom.xml
我已经浏览了谷歌上的信息,之后我试图在pom.xml中添加jackson 2.4,但似乎没有用:
最佳答案
原文链接:https://www.f2er.com/spring/431349.html