我正在使用tomcat web应用程序并休息webservice 当我插入数据时,我得到例外!
我的班级CustomerProxy:
package com.rayanen.java.se.cmsd.proxy;
import com.rayanen.java.se.cmsd.dto.CustomerDTO;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.faces.context.FacesContext;
@Component
public class CustomerProxy implements ICustomerProxy{
@Override
public void insertCustomer(CustomerDTO customerDTO) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
String headerValue = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("cookie");
requestHeaders.add("Cookie", headerValue);
HttpEntity requestEntity = new HttpEntity(customerDTO, requestHeaders);
ResponseEntity response = restTemplate.exchange(
"http://localhost:8080/ws/customer/insert",
HttpMethod.POST,
requestEntity,
CustomerDTO.class);
/*return response.getBody();*/
}
}
class CustomerRestController:
package com.rayanen.java.se.cmsd.ws;
import com.rayanen.java.se.cmsd.dto.CustomerDTO;
import com.rayanen.java.se.cmsd.exceptions.*;
import com.rayanen.java.se.cmsd.facade.facadeimpl.CustomerFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/customer")
public class CustomerRestController {
@Autowired
private CustomerFacade customerFacade;
@RequestMapping(method = RequestMethod.POST, value = "/insert")
ResponseEntity insert(@RequestBody CustomerDTO customerDTO){
try {
customerFacade.save(customerDTO);
} catch (StoreFailedException e) {
e.printStackTrace();
} catch (CustomerIDDuplicateException e) {
e.printStackTrace();
} catch (EmailNotValidException e) {
e.printStackTrace();
} catch (CustomerIDNotValidExeption customerIDNotValidExeption) {
customerIDNotValidExeption.printStackTrace();
} catch (LastNameNotValidException e) {
e.printStackTrace();
} catch (NameNotValidException e) {
e.printStackTrace();
}
return new ResponseEntity(HttpStatus.OK);
}
}
class CustomerBean:
package com.rayanen.java.se.cmsd.webui;
import com.rayanen.java.se.cmsd.dto.CustomerDTO;
import com.rayanen.java.se.cmsd.exceptions.*;
import com.rayanen.java.se.cmsd.facade.facadeimpl.CustomerFacade;
import com.rayanen.java.se.cmsd.proxy.ICustomerProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import java.io.Serializable;
@Component
@Scope("view")
public class CustomerBean implements Serializable{
private CustomerDTO customerDTO = new CustomerDTO();
private String lable;
@Autowired
private CustomerFacade customerFacade;
@Autowired
private ICustomerProxy iCustomerProxy;
public String getLable() {
return lable;
}
public void setLable(String lable) {
this.lable = lable;
}
public CustomerDTO getCustomerDTO() {
return customerDTO;
}
public void setCustomerDTO(CustomerDTO customerDTO) {
this.customerDTO = customerDTO;
}
public void insert(ActionEvent actionEvent){
lable = customerDTO.getName() + "; " + customerDTO.getLastName();
iCustomerProxy.insertCustomer(customerDTO);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Added Successfully", ""));
}
}
和插入我调试和查找异常的数据后的Exeption是这样的:
RestTemplate restTemplate = new RestTemplate();
2017年11月20日23:06:04.211警告[http-nio-8080-exec-5] com.sun.faces.lifecycle.InvokeApplicationPhase.execute /customer/insert.xhtml @ 43,434 的ActionListener ="#{customerBean.insert}&#34 ;: java.lang.NoClassDefFoundError: org / springframework / core / KotlinDetector javax.el.ELException: /customer/insert.xhtml @ 43,434 的ActionListener ="#{customerBean.insert}&#34 ;: java.lang.NoClassDefFoundError: org / springframework / core / KotlinDetector at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111) 在 javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147) 在javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) 在 javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813) 在javax.faces.component.UICommand.broadcast(UICommand.java:300)at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) 在 javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) 在 com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 在javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 com.rayanen.java.se.cmsd.webui.LoginFilter.doFilter(LoginFilter.java:30) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 在 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) 在 org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:673) 在 org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1500) 在 org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1456) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:624) 在 org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:748)引起: java.lang.NoClassDefFoundError: org / springframework / core / KotlinDetector at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:766) 在 org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:619) 在 org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:602) 在 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter。(MappingJackson2HttpMessageConverter.java:59) 在 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter。(AllEncompassingFormHttpMessageConverter.java:67) 在 org.springframework.web.client.RestTemplate。(RestTemplate.java:171) 在 com.rayanen.java.se.cmsd.proxy.CustomerProxy.insertCustomer(CustomerProxy.java:22) 在 com.rayanen.java.se.cmsd.webui.CustomerBean.insert(CustomerBean.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)at org.apache.el.parser.AstValue.invoke(AstValue.java:247)at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267) 在 com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) ... 34更多引起:java.lang.ClassNotFoundException: org.springframework.core.KotlinDetector at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) 在 org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) ......还有49个
任何帮助都将不胜感激。
答案 0 :(得分:2)
是的,正如@Kayaman在评论中指出的那样,添加spring core依赖应该解决它。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
答案 1 :(得分:0)
问题出在我的其他依赖版本上 我改变了它们并解决了问题