Java JSP和Spring启动时出现意外错误(404未找到)
当我试图将一个项目翻译成SpringBoot时,我遇到了一个错误——我无法理解我做错了什么。 将后缀和前缀添加到属性文件中,试图更改jsp的位置,debager显示在控制器的方法中。 我做错了什么?如果有任何帮助,我将不胜感激 错误: 此应用程序没有显式映射的白标签错误页 /错误,因此您将此视为一种回退 2018年7月17日星期二00:45:23出现意外错误(类型=非 已找到,状态为404)/Authorization.jsp 我目前的项目结构: pom.xml: Sping安全配置:(以防万一) 控制器的方法:Java JSP和Spring启动时出现意外错误(404未找到),java,spring,spring-boot,Java,Spring,Spring Boot,当我试图将一个项目翻译成SpringBoot时,我遇到了一个错误——我无法理解我做错了什么。 将后缀和前缀添加到属性文件中,试图更改jsp的位置,debager显示在控制器的方法中。 我做错了什么?如果有任何帮助,我将不胜感激 错误: 此应用程序没有显式映射的白标签错误页 /错误,因此您将此视为一种回退 2018年7月17日星期二00:45:23出现意外错误(类型=非 已找到,状态为404)/Authorization.jsp 我目前的项目结构: pom.xml: Sping安全配置:(以防万一
@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.preffix
到spring.mvc.view.prefix将请求映射到“/auth”并访问请求“Authorization.jsp”。您的请求应该是localhost:port/auth@AmithKumar不,不是。看起来就是这样。事实上,directory PAT和其他jsp都位于同一级别。在那个文件夹中是header.jsp和footer.jsp。@AmithKumar我有Spring Boot应用程序:我的配置是application.properties,我的应用程序从类UquizaApplication开始,我是adeed@AmithKumarurl,我点击的是什么?为什么?我们必须转到jsp页面,查看get请求。如果我们重定向到地址,它如何理解访问Authorization.jsp?地址的必要性,like:localhost:8080/auth-由Spring Boot中内置的ApacheTomcat形成如果您直接想要访问jsp页面,那么使用curl作为like ip:port/:-我认为位置jsp页面的结构和前缀存在问题。应该不用“瓷砖/普通”就可以工作谢谢!这就是解决办法!
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);
}
}