gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:05:48 25 4
gpt4 key购买 nike

当我尝试将项目转换为 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 herepom.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com