spring启动在初始化spring dispatcherservlet时卡住了

j8yoct9x  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(1424)

我是SpringBoot的新手,我正在尝试开发一个用户注册和登录系统。
在eclipse上运行程序后,程序启动成功; Started CustomerApplication in 2.318 seconds (JVM running for 2.938) .
但问题是,当我尝试从浏览器访问页面时,它会不断加载我的thymeleaf页面。
控制台上写着: Initializing Spring DispatcherServlet 'dispatcherServlet' 我的 useraccountcontroller.java 控制器类:

@Controller
public class UserAccountController {

    @Autowired
    private CustomerRepository userRepository;

    @Autowired
    private ConfirmationTokenRepository confirmationTokenRepository;

    @Autowired
    private EmailSenderService emailSenderService;

    @RequestMapping(value="/register", method = RequestMethod.GET)
    public ModelAndView displayRegistration(ModelAndView modelAndView, Customer user)
    {
        modelAndView.addObject("user", user);
        modelAndView.setViewName("register");
        return modelAndView;
    }

    @RequestMapping(value="/register", method = RequestMethod.POST)
    public ModelAndView registerUser(ModelAndView modelAndView, Customer user)
    {

        Customer existingUser = userRepository.findByEmailIdIgnoreCase(user.getEmailId());
        if(existingUser != null)
        {
            modelAndView.addObject("message","This email already exists!");
            modelAndView.setViewName("error"); 
        }
        else
        {
            userRepository.save(user);

            ConfirmationToken confirmationToken = new ConfirmationToken(user);

            confirmationTokenRepository.save(confirmationToken);

            SimpleMailMessage mailMessage = new SimpleMailMessage();
            mailMessage.setTo(user.getEmailId());
            mailMessage.setSubject("Complete Registration!");
            mailMessage.setFrom("rukshan033@gmail.com");
            mailMessage.setText("To confirm your account, please click here : "
            +"http://localhost:8082/confirm-account?token="+confirmationToken.getConfirmationToken());

            emailSenderService.sendEmail(mailMessage);

            modelAndView.addObject("emailId", user.getEmailId());

            modelAndView.setViewName("successfulRegisteration");
        }

        return modelAndView;
    }

    @RequestMapping(value="/confirm-account", method= {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView confirmUserAccount(ModelAndView modelAndView, @RequestParam("token")String confirmationToken)
    {
        //System.out.println("tokkon issa0: "+confirmationToken);
        ConfirmationToken token = confirmationTokenRepository.findByConfirmationToken(confirmationToken);

        if(token != null)
        {
            //System.out.println("tokkon issa1: "+token);
            Customer user = token.getCustomer();
            //Customer user = userRepository.findByEmailIdIgnoreCase(token.getCustomer().getEmailId());
            user.setEnabled(true);
            userRepository.save(user);
            modelAndView.setViewName("accountVerified");
        }
        else
        {
            //System.out.println("tokkon issa2: "+token);
            modelAndView.addObject("message","The link is invalid or broken!");
            modelAndView.setViewName("error");
        }

        return modelAndView;
    }

    @RequestMapping(value="/login", method= {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView login(ModelAndView modelAndView, @RequestParam("emailID")String email, @RequestParam("password")String password)
    {
        Customer user = userRepository.findByEmailIdIgnoreCase(email);

        if(user == null) {
            modelAndView.addObject("message1","Invalid E-mail. Please try again.");
            modelAndView.setViewName("login");
        }
        /*else if (user != null && user.getPassword()!=password) {
            modelAndView.addObject("message1","Incorrect password. Please try again.");
            modelAndView.setViewName("login");
        }
        else if (user != null && user.getPassword()==password && user.isEnabled()==false) {
            modelAndView.addObject("message1","E-mail is not verified. Check you inbox for the verification link.");
            modelAndView.setViewName("login");
        }*/
        else if (user != null && user.getPassword()==password) { //////////////////////////////////////////////////////////////
            modelAndView.addObject("message1","Welcome! You are logged in.");
            modelAndView.setViewName("customerAccount");
        }
        return modelAndView;
    }
    // getters and setters
    public CustomerRepository getUserRepository() {
        return userRepository;
    }

    public void setUserRepository(CustomerRepository userRepository) {
        this.userRepository = userRepository;
    }

    public ConfirmationTokenRepository getConfirmationTokenRepository() {
        return confirmationTokenRepository;
    }

    public void setConfirmationTokenRepository(ConfirmationTokenRepository confirmationTokenRepository) {
        this.confirmationTokenRepository = confirmationTokenRepository;
    }

    public EmailSenderService getEmailSenderService() {
        return emailSenderService;
    }

    public void setEmailSenderService(EmailSenderService emailSenderService) {
        this.emailSenderService = emailSenderService;
    }

}

我的 register.html 第页:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
  xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="utf-8" />
        <title>Registration</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <!-- MATERIAL DESIGN ICONIC FONT -->
        <link rel="stylesheet" th:href="@{fonts/material-design-iconic-font/css/material-design-iconic-font.min.css}" ></link>
        <!-- Favicon -->
        <link th:href="@{img/favicon.ico}" rel="shortcut icon"></link>

        <!-- Google Font -->
        <link th:href="@{https:fonts.googleapis.com/css?family=Josefin+Sans:300,300i,400,400i,700,700i}" rel="stylesheet" ></link>
        <!-- STYLE CSS -->
        <link th:href="@{/css/regstyle.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/style.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/font-awesome.min.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/flaticon.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/slicknav.min.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/jquery-ui.min.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/owl.carousel.min.css}" rel="stylesheet" ></link>
        <link th:href="@{/css/animate.css}" rel="stylesheet" ></link>
    </head>

    <body>
        <!-- Page Preloder -->
    <div id="preloder">
        <div class="loader"></div>
    </div>

    <!-- Header section -->
    <header class="header-section">
        <div class="header-top">
            <div class="container">
                <div class="row">
                    <div class="col-lg-2 text-center text-lg-left">
                        <!-- logo -->
                        <a href="./index.html" class="site-logo">
                            <img src="/img/logo.png" alt=""></img>
                        </a>
                    </div>
                    <div class="col-xl-6 col-lg-5">
                        <form class="header-search-form">
                            <input type="text" placeholder="Search on divisima ...." /></input>
                            <button><i class="flaticon-search"></i></button>
                        </form>
                    </div>
                    <div class="col-xl-4 col-lg-5">
                        <div class="user-panel">
                            <div class="up-item">
                                <i class="flaticon-profile"></i>
                                <a href="login.html">Sign</a> In or <a href="#">Create Account</a>
                            </div>
                            <div class="up-item">
                                <div class="shopping-card">
                                    <i class="flaticon-bag"></i>
                                    <span>0</span>
                                </div>
                                <a href="#">Shopping Cart</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <nav class="main-navbar">
            <div class="container">
                <!-- menu -->
                <ul class="main-menu">
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Women</a></li>
                    <li><a href="#">Men</a></li>
                    <li><a href="#">Jewelry
                        <span class="new">New</span>
                    </a></li>
                    <li><a href="#">Shoes</a>
                        <ul class="sub-menu">
                            <li><a href="#">Sneakers</a></li>
                            <li><a href="#">Sandals</a></li>
                            <li><a href="#">Formal Shoes</a></li>
                            <li><a href="#">Boots</a></li>
                            <li><a href="#">Flip Flops</a></li>
                        </ul>
                    </li>
                    <li><a href="#">Pages</a>
                        <ul class="sub-menu">
                            <li><a href="./product.html">Product Page</a></li>
                            <li><a href="./category.html">Category Page</a></li>
                            <li><a href="./cart.html">Cart Page</a></li>
                            <li><a href="./checkout.html">Checkout Page</a></li>
                            <li><a href="./contact.html">Contact Page</a></li>
                        </ul>
                    </li>
                    <li><a href="#">Blog</a></li>
                </ul>
            </div>
        </nav>
    </header>
    <!-- Header section end -->

        <div class="wrapper" style="background-image: url('images/bg-registration-form-2.jpg');">
            <div class="inner">
                <form action="#" th:action="@{/register}" th:object="${user}" method="post">
                    <h3>Registration Form</h3>
                    <div class="form-group">
                        <div class="form-wrapper">
                            <label for="firstName">First Name</label>
                            <input th:field="*{firstName}" type="text" name="firstName" class="form-control" ></input>
                        </div>
                        <div class="form-wrapper">
                            <label for="lastName">Last Name</label>
                            <input th:field="*{lastName}" type="text" name="lastName" class="form-control" ></input>
                        </div>
                    </div>
                    <div class="form-wrapper">
                        <label for="dob">Date of Birth</label>
                        <input th:field="*{dob}" type="date" name="dob" class="form-control" ></input>
                    </div>
                    <div class="form-wrapper">
                        <label for="telephone">Telephone</label>
                        <input th:field="*{telephone}" type="text" name="telephone" class="form-control" ></input>
                    </div>
                    <div class="form-wrapper">
                        <label for="emailId">Email</label>
                        <input th:field="*{emailId}" type="email" name="emailId" class="form-control" ></input>
                    </div>
                    <div class="form-group">
                        <div class="form-wrapper">
                            <label for="street">Street</label>
                            <input th:field="*{street}" type="text" name="street" class="form-control" ></input>
                        </div>
                        <div class="form-wrapper">
                            <label for="city">City</label>
                            <input th:field="*{city}" type="text" name="city" class="form-control" ></input>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="form-wrapper">
                            <label for="district">District</label>
                            <input th:field="*{district}" type="text" name="district" class="form-control" ></input>
                        </div>
                        <div class="form-wrapper">
                            <label for="province">Province</label>
                            <input th:field="*{province}" type="text" name="province" class="form-control" ></input>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="form-wrapper">
                            <label for="password">Password</label>
                            <input th:field="*{password}" type="password" name="password" class="form-control" ></input>
                        </div>
                        <div class="form-wrapper">
                            <label for="">Confirm Password</label>
                            <input type="password" class="form-control" ></input>
                        </div>
                    </div>
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" ></input> I accept the Terms of Use & Privacy Policy.
                            <span class="checkmark"></span>
                        </label>
                    </div>
                    <button>Register Now</button>               

                </form>
            </div>
        </div>

            <!-- Footer section -->
    <section class="footer-section">
        <div class="container">
            <div class="footer-logo text-center">
                <a href="index.html"><img src="/img/logo-light.png" alt="" ></img></a>
            </div>
            <div class="row">
                <div class="col-lg-3 col-sm-6">
                    <div class="footer-widget about-widget">
                        <h2>About</h2>
                        <p>Donec vitae purus nunc. Morbi faucibus erat sit amet congue mattis. Nullam frin-gilla faucibus urna, id dapibus erat iaculis ut. Integer ac sem.</p>
                        <img src="img/cards.png" alt="" /></img>
                    </div>
                </div>
                <div class="col-lg-3 col-sm-6">
                    <div class="footer-widget about-widget">
                        <h2>Questions</h2>
                        <ul>
                            <li><a href="">About Us</a></li>
                            <li><a href="">Track Orders</a></li>
                            <li><a href="">Returns</a></li>
                            <li><a href="">Jobs</a></li>
                            <li><a href="">Shipping</a></li>
                            <li><a href="">Blog</a></li>
                        </ul>
                        <ul>
                            <li><a href="">Partners</a></li>
                            <li><a href="">Bloggers</a></li>
                            <li><a href="">Support</a></li>
                            <li><a href="">Terms of Use</a></li>
                            <li><a href="">Press</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col-lg-3 col-sm-6">
                    <div class="footer-widget about-widget">
                        <h2>Questions</h2>
                        <div class="fw-latest-post-widget">
                            <div class="lp-item">
                                <div class="lp-thumb set-bg" data-setbg="img/blog-thumbs/1.jpg"></div>
                                <div class="lp-content">
                                    <h6>what shoes to wear</h6>
                                    <span>Oct 21, 2018</span>
                                    <a href="#" class="readmore">Read More</a>
                                </div>
                            </div>
                            <div class="lp-item">
                                <div class="lp-thumb set-bg" data-setbg="img/blog-thumbs/2.jpg"></div>
                                <div class="lp-content">
                                    <h6>trends this year</h6>
                                    <span>Oct 21, 2018</span>
                                    <a href="#" class="readmore">Read More</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-sm-6">
                    <div class="footer-widget contact-widget">
                        <h2>Questions</h2>
                        <div class="con-info">
                            <span>C.</span>
                            <p>Your Company Ltd </p>
                        </div>
                        <div class="con-info">
                            <span>B.</span>
                            <p>1481 Creekside Lane  Avila Beach, CA 93424, P.O. BOX 68 </p>
                        </div>
                        <div class="con-info">
                            <span>T.</span>
                            <p>+53 345 7953 32453</p>
                        </div>
                        <div class="con-info">
                            <span>E.</span>
                            <p>office@youremail.com</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="social-links-warp">
            <div class="container">
                <div class="social-links">
                    <a href="" class="instagram"><i class="fa fa-instagram"></i><span>instagram</span></a>
                    <a href="" class="google-plus"><i class="fa fa-google-plus"></i><span>g+plus</span></a>
                    <a href="" class="pinterest"><i class="fa fa-pinterest"></i><span>pinterest</span></a>
                    <a href="" class="facebook"><i class="fa fa-facebook"></i><span>facebook</span></a>
                    <a href="" class="twitter"><i class="fa fa-twitter"></i><span>twitter</span></a>
                    <a href="" class="youtube"><i class="fa fa-youtube"></i><span>youtube</span></a>
                    <a href="" class="tumblr"><i class="fa fa-tumblr-square"></i><span>tumblr</span></a>
                </div>

<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. --> 
<p class="text-white text-center mt-5">Copyright &copy;<script>document.write(new Date().getFullYear());</script> All rights reserved | This template is made with <i class="fa fa-heart-o" aria-hidden="true"></i> by <a href="https://colorlib.com" target="_blank">Colorlib</a></p>
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->

            </div>
        </div>
    </section>
    <!-- Footer section end -->

    <!--====== Javascripts & Jquery ======-->
    <script type="text/javascript" src="@{/js/jquery-3.2.1.min.js}"></script>
    <script type="text/javascript" src="@{/js/bootstrap.min.js}"></script>
    <script type="text/javascript" src="@{/js/jquery.slicknav.min.js}"></script>
    <script type="text/javascript" src="@{/js/owl.carousel.min.js}"></script>
    <script type="text/javascript" src="@{/js/jquery.nicescroll.min.js}"></script>
    <script type="text/javascript" src="@{/js/jquery.zoom.min.js}"></script>
    <script type="text/javascript" src="@{/js/jquery-ui.min.js}"></script>
    <script type="text/javascript" src="@{/js/main.js}"></script>
    </body>
</html>

慰问:

2020-09-05 20:24:26.578  INFO 27384 --- [           main] c.O.customer.CustomerApplication         : Starting CustomerApplication on LAPTOP-D72B23NQ with PID 27384 (C:\Users\User\Desktop\customer\target\classes started by User in C:\Users\User\Desktop\customer)
2020-09-05 20:24:26.579  INFO 27384 --- [           main] c.O.customer.CustomerApplication         : No active profile set, falling back to default profiles: default
2020-09-05 20:24:27.468  INFO 27384 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-09-05 20:24:27.468  INFO 27384 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.36]
2020-09-05 20:24:27.575  INFO 27384 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-09-05 20:24:27.687  INFO 27384 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-09-05 20:24:27.690  WARN 27384 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2020-09-05 20:24:27.776  INFO 27384 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-09-05 20:24:27.849  WARN 27384 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
Hibernate: alter table confirmation_token add constraint FKpitnf1t12om2w2btrcd37gwpq foreign key (user_id) references customer (user_id)
2020-09-05 20:24:28.657  INFO 27384 --- [           main] c.O.customer.CustomerApplication         : Started CustomerApplication in 2.318 seconds (JVM running for 2.938)
2020-09-05 20:24:37.951  INFO 27384 --- [nio-8082-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题