java - JSP 和 Spring Boot 出现意外错误(404 Not Found)

标签 java spring spring-boot

当我尝试将项目转换为 Spring Boot 时,我收到错误 - 我无法理解我做错了什么。 在property-file中添加后缀和前缀,尝试改变jsp的位置,debager显示在 Controller 的方法中。 我做错了什么?我将不胜感激任何帮助

错误:

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

Tue Jul 17 00:45:23 EEST 2018 There was an unexpected error (type=Not Found, status=404). /Authorization.jsp

我当前的项目结构: enter image description here pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.solopov.hillel</groupId>
 <artifactId>uquiz</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>war</packaging>

 <name>uquiz</name>
 <description>The project allows you to create and conduct surveys to anyone who wants</description>

 <parent>
  <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.3.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>

 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-taglibs</artifactId>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
  </dependency>
  <dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
  </dependency>
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
  </dependency>
 </dependencies>

 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>


</project>

Spring Boot application.properties:

logging.level.root = info

spring.mvc.view.preffix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

spring.datasource.url=jdbc:mysql://localhost:3306/quizzes?autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext

Sping 安全配置:(以防万一)

package com.solopov.hillel.uquiz.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import javax.sql.DataSource;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Autowired
    DataSource dataSource;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(new BCryptPasswordEncoder())
            .usersByUsernameQuery("select login,password,true from user where login=?")
             .authoritiesByUsernameQuery("select login, role from user where login=?");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http    .authorizeRequests()
                .antMatchers("/auth", "/reg","/welcomepage").permitAll()
                .antMatchers("/admin/**").hasAuthority("admin")
                .anyRequest().authenticated().and()
                .formLogin()
                .loginPage("/auth").usernameParameter("login")
                .permitAll()
                .and()
                .logout().logoutSuccessUrl("/auth")
                .and().csrf().disable();
    }
}

Controller 方法:

@RequestMapping(method = GET, value = "/auth")
    public String authorization() {
        return "Authorization";
    }

开始上课:

@SpringBootApplication
public class UquizApplication {

 public static void main(String[] args) {
  SpringApplication.run(UquizApplication.class, args);
 }
}

最佳答案

请更正您的属性文件中的拼写错误: spring.mvc.view.prefixspring.mvc.view.prefix

关于java - JSP 和 Spring Boot 出现意外错误(404 Not Found),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51370624/

相关文章:

java - 如何在 thymeleaf Numbers.sequence() 方法中使用 Constants 类中的变量?

java - Spring MVC 'forward' 不适用于同一 URI 的 @PostMapping 和 @GetMapping 注解

java - Spring MVC 3.1 : Problems in using SimpleUrlHandlerMapping and generic base controller

spring-boot - Spring Boot 和 CORS

java - 在 Realm 4.1.1 中查询 RealmList<String> 时出错

java - 良好的 JPA Java 桌面应用程序示例

java - 如何在 TextView 中使用 ClickableSpans 并且仍然能够水平滚动?

Java 泛型 - 综合 "Start to End"指南?

java - 在 Spring Boot 服务中的自定义约束 validator 之前,Json 消息解析失败

升级到 2.4.0 后,Spring Cloud 配置客户端无法从配置服务器获取/加载配置文件