当我尝试将项目转换为Spring Boot时,出现错误-我无法理解我做错了什么。 将后缀和前缀添加到属性文件中,试图更改jsp的位置,debager表明控制器中的方法来了。 我做错了什么?我将不胜感激
错误:
Whitelabel错误页面此应用程序没有针对 /错误,因此您将其视为备用。
2018年7月17日星期二00:45:23发生意外错误(type = Not 找到,状态为404)。 /Authorization.jsp
<?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();
}
}
控制器方法:
@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);
}
}
答案 0 :(得分:1)
请更正属性文件中的错字:
spring.mvc.view.preffix
至spring.mvc.view.prefix
答案 1 :(得分:0)
您将请求映射到“ / auth ”,然后访问请求“ Authorization.jsp ”。您的请求应为 localhost:port / auth