情况:
问题:
问题是,我的控制器调用服务方法后很快(尽快)就抛出异常。它甚至没有达到'log.info'(这是该方法中的第一行代码)。
这应该绝对有效,我会收回它为什么不是。这似乎是一件非常简单的事情。 ie(将数据返回给我的控制器;在调用服务方法时使用该数据)。
CONTROLLER
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerAccount(@ModelAttribute User user, Locale locale,
Model model) {
String theView = "";
try{
logger.info("User submitted Registration Form");
user.setPaidStatus("ACTIVE");
user.setUserRole("SUBSCRIBER");
logger.info(user.toString()); //Proving all the data is available.
userService.createNewUser(user); //This is the call to my service
//method. As soon as it reaches it it exceptions out right away.
//userDao.createNewUser(userDto); //just to see if it does the same
//thing elsewhere - (it does)
model.addAttribute("command", new User());
theView = "login";
} catch(SaveMyFavsException se){
logger.info(se.getCmdCode() + ", Message: " + se.getCmdMsg());
model.addAttribute("command", new User());
model.addAttribute("error", se.getCmdCode() + ", Message: " +
se.getCmdMsg());
return "register";
} catch(Exception e){
logger.info(e.getLocalizedMessage());
model.addAttribute("command", new User());
model.addAttribute("error", e.getLocalizedMessage());
return "register";
}
return theView;
}
服务类(请参阅createNewUser())
@Component
public class UserService implements UserServiceInterface{
@Autowired
UserDaoInterface userDao;
private static final Logger logger = LoggerFactory.getLogger(UserService.class);
public void createNewUser(User user){
int result = 0;
try{
//FAILS BEFORE MAKING IT HERE (automatically ends up in the second Catch block for Exception with no message)
logger.info("Entered createNewUser() service");
logger.info("User ID: " + user.getUserId());
result = userDao.createNewUser(user);
logger.info("New User DAO Complete - Rows Inserted: " + result);
} catch(SaveMyFavsException se){
throw new SaveMyFavsException(se.getCmdCode(), se.getCmdMsg());
} catch(Exception e){
logger.info("General Exception occurred during service to create new user... Trace: " + e.getLocalizedMessage());
throw new SaveMyFavsException(2000015, "General Exception occurred during service to create new user... Trace: " + e.getLocalizedMessage());
}
}
答案 0 :(得分:0)
您没有看到完整的错误消息,因为您正在吃掉完整的堆栈跟踪。将记录器更改为: logger.info(“在创建新用户的服务期间发生一般异常。”,e);
答案 1 :(得分:0)
请分享将userService注入控制器的代码。这似乎是bean注入的一个问题。