【发布时间】:2015-03-18 14:48:45
【问题描述】:
我的@Inject 不适用于我的 Web 服务 (@Path),但可以使用 @WebServlet,为什么?
我的网络服务
@Path("/autenticacao")
public class UsuarioService {
@Inject
private UsuarioRepository usuarioRepository;
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response autentica(@FormParam(value = "cpf") String cpf, @FormParam(value = "senha") String senha){
Usuario usuario = usuarioRepository.getUsuarioByCPFSenha(cpf, senha);
return Response.status(200).entity(usuario).build();
}
}
UsuarioRepository 接口的定义
public interface UsuarioRepository {
public Usuario getUsuarioByCPFSenha(String cpf, String senha);
}
我对@987654324@ 接口的实现
public class UsuarioRepositoryImp implements UsuarioRepository {
@Inject
private Connection connection;
@Override
public Usuario getUsuarioByCPFSenha(String cpf, String senha) {
String SQL = "SELECT se01_cpf, se01_senha FROM se01_usuario WHERE replace(replace(se01_cpf,'.',''),'-','') = ? AND se01_senha = ?";
Usuario usuario = null;
try {
PreparedStatement stmt = connection.prepareStatement(SQL);
stmt.setString(1, cpf);
stmt.setString(2, senha);
ResultSet set = stmt.executeQuery();
while(set.next()){
String c = set.getString("se01_cpf");
String s = set.getString("se01_senha");
usuario = new Usuario(c, s);
}
set.close();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return usuario;
}
}
我的字段usuarioRepository 在我的请求后为空,知道吗?
【问题讨论】: