我正在使用tomcat web应用程序和rest 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();*/
}
}
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);
}
}
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", ""));
}
}
RestTemplate restTemplate = new RestTemplate();
是的,正如@kayaman在评论中指出的,添加spring核心依赖应该可以解决它。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
我需要一个用于私有方法测试的powermock 如果我只使用@RunWith(PowerMockRunner.class)而不使用@powermockrunnerregate(SpringJUnit4ClassRunner.class),效果会很好 我需要使用@powermockrunnerregate(SpringJUnit4ClassRunner.class)来表示@autowired。但它并
我正在尝试基于此示例编写自己的代码。 我使用的是Spring Boot,所有依赖项都来自https://start.spring.io/ 这是我的知识库: 我的控制器的一部分: 我的Spring Boot: 我收到此错误: 我做错了什么?如果有必要,我可以发布更多类似实体的代码 我正在使用IntelliJ IDEA。
错误: 2月19日-2016 00:00:16.731SEVERE[localhost]org.apache.catalina.core.Applicationontext.logStandard ardWrapper。可投掷org.springframework.beans.factory.BeanCreationException:创建名称为“人员服务”的bean时出错:自动加载依赖项注入失败
问题内容: 我目前正在尝试在构建服务器(Windows Server R2)上创建Jenkins CI作业,事实证明,这需要进行更多工作才能安装Visual Studio。为此,我尝试使用Visual Studio项目中的.csproj文件构建Web包。这是我在詹金斯(Jenkins)中的MSBuild操作设置的外观: 运行构建时发生的错误是这样的: C:\ Program Files(x86)\
你好,我是android中MVVM的新手,正在使用livedata。我正在尝试创建viewmodel的一个实例。我觉得问题在于我没有将存储库传递给viewmodel构造函数。我一直无法创建viewmodel的实例。我不知道该怎么做这里是我的viewmodel和它的创建。
我正在使用spring boot和Ignite数据库 我只创建了一个存储库,我正在Pojo中设置数据,以便使用IgniteRepository保存 下面是Ignite with Spring所需的依赖项:Ignite Version::2.0.0 这里我使用的是H2数据库依赖项,如果不使用它,我会收到另一个完全未知的错误。 点火配置: 用户POJO: 运行后,我得到错误: