我的第一个 Spring WS 项目有问题。我想使用 spring ws 来分离 GUI 和 DAO。因为那根本不起作用,所以首先我想在一个项目中实现 WS。我目前的问题是我得到了例外:
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8443/shadowrun/user/Markus2/test":Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:503)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:452)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:222)
at at.itn.shadowrun.gui.service.client.UserClient.findUser(UserClient.java:26)
这是来自UserClient.java的部分:
@Component("userClient")
public class UserClient extends GenericClient {
@Autowired
public UserClient(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public SUsers findUser(String user, String password) {
return restTemplate.getForObject(serviceUrl + "user/{user}/{password}", SUsers.class, user, password);
}
// etc
}
最后是加载UserClient.java的SignInSession.java:
public final class SignInSession extends AuthenticatedWebSession {
@Autowired
private UserClient userClient = new UserClient(new RestTemplate());
@Override
public final boolean authenticate(final String username, final String password) {
currentUser = userClient.findUser(username, password);
// etc
}
}
到目前为止我的想法:我发现我必须编写private UserClient userClient = new UserClient(new RestTemplate());
来防止 NullPointerException 有点令人困惑,但在所有教程中我发现它总是只声明@Autowired private UserClient userClient
.
谁能给我一些指导和/或一些关于此的推荐文档?谢谢!