Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录时出现java.lang.StackOverflower错误_Java_Spring Boot_Spring Mvc_Spring Security - Fatal编程技术网

登录时出现java.lang.StackOverflower错误

登录时出现java.lang.StackOverflower错误,java,spring-boot,spring-mvc,spring-security,Java,Spring Boot,Spring Mvc,Spring Security,我正在为我的项目使用SpringBootStarter安全和验证api。以前我的项目运行正常,用户可以注册到注册页面,数据正确存储在数据库中。为了登录,我做了一个自定义的登录页面,我可以登录,但我不知道发生了什么错误。现在显示stackoverflow错误 UserController.java @Controller @RequestMapping("/user") public class UserController { @Autowired

我正在为我的项目使用SpringBootStarter安全和验证api。以前我的项目运行正常,用户可以注册到注册页面,数据正确存储在数据库中。为了登录,我做了一个自定义的登录页面,我可以登录,但我不知道发生了什么错误。现在显示stackoverflow错误

UserController.java

@Controller
@RequestMapping("/user")
public class UserController {
    
    @Autowired
     UserRepository userRepository;
    
    
    
    
    @ModelAttribute
    public void addCommonData(Model model,Principal principal) {
    String userName = principal.getName();
        
        User user = userRepository.getUSerByUserName(userName);
        //debug in console
        System.out.println("user " + user);
        
        
        
        model.addAttribute("user",user);
    }
    
    
    
    @RequestMapping("/index")
    public String dashboard(Model model ,Principal principal) {
        
        model.addAttribute("title","User Dashboard");
        return "normal/user_dashboard";
    }
    
    
    
    @GetMapping("/add-contact")
    public String openAddContactForm(Model model) {
        
        model.addAttribute("title", "Add Contact");
        
        model.addAttribute("contact",new Contact());
        
        return "normal/add_contact_form";
    }
    
    

}
我不明白哪里出错了。请提供帮助,我还可以提供UserDetails和UserDetailsService接口的实现代码。 我正在使用以下依赖项 1.spring-boot-starter-data-jpa 2.spring-boot-starter-thymeleaf 3.spring-boot-starter-web 4.spring-boot-starter-security 5.spring-boot-devtools 6.1-api验证 7.hibernate-validator 8.mysql-connector-java

对于授权部分,我提供了Myconfig.java中的代码。。请帮忙,我不明白是什么错误

error
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Nov 15 21:48:55 NPT 2020
There was an unexpected error (type=Internal Server Error, status=500).
No message available
java.lang.StackOverflowError

表单的Url和操作都是正确的

HomeController.java   for remaining pages and request

@Controller
public class HomeController {
    
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;
    
    @Autowired
    UserRepository  userRepo;
    
    @RequestMapping("/")
    public String home(Model model) {
        model.addAttribute("title","Home-Smart Contact Manager");
        return "home";
    }
    
    
    @RequestMapping("/about")
    public String about(Model model) {
        model.addAttribute("title","About-Smart Contact Manager");
        return "about";
    }
    

    @RequestMapping("/signup")
    public String signup(Model model) {
        model.addAttribute("title","Register-Smart Contact Manager");
        model.addAttribute("user",new User());
        return "signup";
    }
    
    
    //hander for registering user
    @RequestMapping(value="/do_register",method=RequestMethod.POST)
    public String registerUser(@Valid @ModelAttribute("user")User user,BindingResult result ,
            @RequestParam(value="agreement",defaultValue="false") boolean agreement, 
            Model model, HttpSession session)
    {
        try {
            
            //check gryoki nai vnyrw validation nai ho
            if(!agreement)
            {
                System.out.println("you haven't agreed the terms and conditions");
                throw new Exception("You haven't agreed the terms and conditions");
            }
            
            
            //if invalid data pathako xa vnya error aauxa
            if(result.hasErrors()) {
                
                model.addAttribute("user",user); //we have send user obj to the view 
                return "signup";
            }
            
                
            //yadi error xa vana back to the form with user input data sajilo
            
            user.setRole("ROLE_USER");
            user.setEnabled(true);
            user.setImageUrl("default.png");
            user.setPassword(passwordEncoder.encode(user.getPassword()));
            
            System.out.println("agreement "+ agreement);
            System.out.println("User "+ user);
            
            
            
            User result1 = this.userRepo.save(user);
            model.addAttribute("user",new User());
            session.setAttribute("message", new Message("Successfully Registered!!","alert-success"));
            return "signup";
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
            model.addAttribute("user",user);
            session.setAttribute("message", new Message("Something Went Wrong !! " + e.getMessage(),"alert-danger"));
            return "signup";
        }
        
    }

    
    
    
    //handler for custom login
    @GetMapping("/signin")
    public String customLogin(Model model) {
        
        model.addAttribute("title","Login Page - Smart Contact Manager");
        return "login";
    }
    

}

如果您正在使用thymeleaf或velocity,请添加有关该项目的更多信息,是否有其他配置或过滤器。依赖项1.spring-boot-starter-data-jpa 2.spring-boot-starter-thymeleaf 3.spring-boot-starter-web 4.spring-boot-starter-security 5.spring-boot-devtools 6.validation-api 7.hibernate-validato 8.mysql-connector-java。添加有关该项目的更多信息,如果您使用的是thymeleaf或velocity,是否有其他配置或过滤器。Dependencies 1.spring-boot-starter-data-jpa 2.spring-boot-starter-thymeleaf 3.spring-boot-starter-web 4.spring-boot-starter-security 5.spring-boot-devtools 6.validation-api 7.hibernate-validato 8.mysql-connector-java。
HomeController.java   for remaining pages and request

@Controller
public class HomeController {
    
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;
    
    @Autowired
    UserRepository  userRepo;
    
    @RequestMapping("/")
    public String home(Model model) {
        model.addAttribute("title","Home-Smart Contact Manager");
        return "home";
    }
    
    
    @RequestMapping("/about")
    public String about(Model model) {
        model.addAttribute("title","About-Smart Contact Manager");
        return "about";
    }
    

    @RequestMapping("/signup")
    public String signup(Model model) {
        model.addAttribute("title","Register-Smart Contact Manager");
        model.addAttribute("user",new User());
        return "signup";
    }
    
    
    //hander for registering user
    @RequestMapping(value="/do_register",method=RequestMethod.POST)
    public String registerUser(@Valid @ModelAttribute("user")User user,BindingResult result ,
            @RequestParam(value="agreement",defaultValue="false") boolean agreement, 
            Model model, HttpSession session)
    {
        try {
            
            //check gryoki nai vnyrw validation nai ho
            if(!agreement)
            {
                System.out.println("you haven't agreed the terms and conditions");
                throw new Exception("You haven't agreed the terms and conditions");
            }
            
            
            //if invalid data pathako xa vnya error aauxa
            if(result.hasErrors()) {
                
                model.addAttribute("user",user); //we have send user obj to the view 
                return "signup";
            }
            
                
            //yadi error xa vana back to the form with user input data sajilo
            
            user.setRole("ROLE_USER");
            user.setEnabled(true);
            user.setImageUrl("default.png");
            user.setPassword(passwordEncoder.encode(user.getPassword()));
            
            System.out.println("agreement "+ agreement);
            System.out.println("User "+ user);
            
            
            
            User result1 = this.userRepo.save(user);
            model.addAttribute("user",new User());
            session.setAttribute("message", new Message("Successfully Registered!!","alert-success"));
            return "signup";
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
            model.addAttribute("user",user);
            session.setAttribute("message", new Message("Something Went Wrong !! " + e.getMessage(),"alert-danger"));
            return "signup";
        }
        
    }

    
    
    
    //handler for custom login
    @GetMapping("/signin")
    public String customLogin(Model model) {
        
        model.addAttribute("title","Login Page - Smart Contact Manager");
        return "login";
    }
    

}