Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java DispatcherServlet can';无法获取配置类_Java_Spring Boot_Spring Mvc_Jetty - Fatal编程技术网

Java DispatcherServlet can';无法获取配置类

Java DispatcherServlet can';无法获取配置类,java,spring-boot,spring-mvc,jetty,Java,Spring Boot,Spring Mvc,Jetty,今天我想尝试java并开始使用SpringMVC(basic)。我在尝试使用Jetty(v9.4.21.v20190926)运行src时遇到问题。我不知道为什么DispatcherServlet不能加载配置类 我研究了一些东西,我试图解决,但什么也没发生:( 我在下面有一些文件配置: servletilizer.java package com.examples.spring.config; 导入org.springframework.context.annotation.Configurati

今天我想尝试java并开始使用SpringMVC(basic)。我在尝试使用Jetty(v9.4.21.v20190926)运行src时遇到问题。我不知道为什么DispatcherServlet不能加载配置类

我研究了一些东西,我试图解决,但什么也没发生:(

我在下面有一些文件配置: servletilizer.java

package com.examples.spring.config;
导入org.springframework.context.annotation.Configuration;
导入org.springframework.web.servlet.support.AbstractAnnotationConfigDispatchersServletInitializer;
@配置
公共类ServletInitializer扩展了AbstractAnnotationConfigDispatchers ServletInitializer{
@凌驾
受保护类[]getRootConfigClasses(){
返回新类[]{SecurityConfig.Class,WebConfig.Class};
}
@凌驾
受保护类[]getServletConfigClasses(){
返回null;
}
@凌驾
受保护的字符串[]getServletMappings(){
返回新字符串[]{”/“};
}
}
WebConfig.java

package com.examples.spring.config;
导入org.springframework.context.annotation.Bean;
导入org.springframework.context.annotation.ComponentScan;
导入org.springframework.context.annotation.Configuration;
导入org.springframework.web.servlet.config.annotation.EnableWebMvc;
导入org.springframework.web.servlet.config.annotation.WebMVCConfiguer;
导入org.springframework.web.servlet.view.freemarker.freemarkerconfiguer;
导入org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
@配置
@EnableWebMvc
@ComponentScan(basePackages={“com.examples.spring”})
公共类WebConfig实现WebMVCConfiguer{
@豆子
公共freemarkervewersolver freemarkervewersolver(){
FreeMarkerViewResolver解析器=新的FreeMarkerViewResolver();
resolver.setCache(true);
分解器。设置固定装置(“ftl”);
返回解析器;
}
@豆子
public freemarkerconfiguer freemarkerConfig(){
freemarkerconfiguer freemarkerconfiguer=新的freemarkerconfiguer();
freemarkerconfiguer.setTemplateLoaderPath(“/WEB-INF/ftl/”);
返回freemarkerconfiguer;
}
}
SecurityConfig.java

package com.examples.spring.config;
导入org.springframework.context.annotation.Bean;
导入org.springframework.context.annotation.Configuration;
导入org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
导入org.springframework.security.config.annotation.web.builders.HttpSecurity;
导入org.springframework.security.config.annotation.web.builders.WebSecurity;
导入org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
导入org.springframework.security.config.annotation.web.configuration.websecurityConfigureAdapter;
导入org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
导入org.springframework.security.crypto.password.PasswordEncoder;
导入org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@配置
@启用Web安全性
公共类SecurityConfig扩展了WebSecurity配置适配器{
@凌驾
受保护的无效配置(最终身份验证ManagerBuilder身份验证)引发异常{
auth.inMemoryAuthentication().withUser(“admin”).passwordEncoder().encode(“admin”).roles(“admin”);
}
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
//http.csrf().disable();
http.authorizeRequests()
//配置未经身份验证的路径
.antMatchers(“/”).permitAll()
.antMatchers(“/login”).permitAll()
.antMatchers(“/注册”).permitAll()
//配置验证路径
.antMatchers(“/admin/**”).hasAuthority(“admin”).anyRequest()
.authenticated()和().formLogin()
//配置登录成功&重定向失败
.failureUrl(“/login?error=true”)
.defaultSuccessUrl(“/admin”)
//配置访问被拒绝的路径
.和().例外处理()
.accessDeniedPage(“/access denied”)
//配置登录路径
//.login页面(“/login”)
//.usernameParameter(“电子邮件”)
//.passwordParameter(“密码”)
//配置注销路径
。和()。注销()
.logoutRequestMatcher(新的AntPathRequestMatcher(“/logout”))
.deleteCookies(“JSSessionID”)
.logoutSuccessUrl(“/”);
}
@凌驾
public void configure(WebSecurity web)引发异常{
忽略();
}
@豆子
公共密码编码器PasswordEncoder(){
返回新的BCryptPasswordEncoder();
}
}

我看不出我的文件有问题,但当我使用Jetty运行项目时,SecurityConfig.class无法加载,到Spring Boot时,我的代码工作正常没有问题:(.我只是一个新手,请向我解释问题,谢谢。

您可能遇到了一个bug,请改用Jetty 9.4.22.v20191022。谢谢,我将尝试另一个Jetty版本