老师 您好,请问我再学习4-4章结尾的时候写到properties时,项目启动不了了
来源:4-4 个性化用户认证流程(一)

Qolome
2018-03-08
一直报错:
BrowserSecurityConfig.Class 代码如下
package com.ginger.security.browser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import com.ginger.security.core.properties.SecurityProperties; @Configuration public class BrowserSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private SecurityProperties securityProperties; @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Override protected void configure(HttpSecurity http) throws Exception { http.formLogin() .loginPage("authentication/require") .loginProcessingUrl("/authentication/form") .and() .authorizeRequests() .antMatchers("authentication/require",securityProperties.getBrowser().getLoginPage()).permitAll() .anyRequest() .authenticated() .and() .csrf().disable(); } }
SecurityProperties.Class 代码如下
package com.ginger.security.core.properties; import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "ginger.security") public class SecurityProperties { private BrowserProperties browser = new BrowserProperties(); public BrowserProperties getBrowser() { return browser; } public void setBrowser(BrowserProperties browser) { this.browser = browser; } }
运行报错:
Description:Field securityProperties in com.ginger.security.browser.BrowserSecurityConfig required a bean of type 'com.ginger.security.core.properties.SecurityProperties' that could not be found.
Action:Consider defining a bean of type 'com.ginger.security.core.properties.SecurityProperties' in your configuration.
打包报错:
[
ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
写回答
2回答
-
报错是说SecurityProperties这个bean不存在,应该是启动类没扫描到这个类,注意启动类要在组件类的父包里,比如 'com.ginger.security.core.properties.SecurityProperties' 这个类,默认情况下,程序的启动类,一定要在他的父包里,比如 'com.ginger'包里,才能扫描到它。
122018-03-20 -
Qolome
提问者
2018-03-20
package com.ginger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * * @Description: SpringBoot启动 * @author 姜锋 * @date 2018年2月12日 下午4:31:08 * @version V1.0 * */ @SpringBootApplication @RestController @EnableSwagger2 public class GingerApplication { public static void main(String[] args) { SpringApplication.run(GingerApplication.class, args); } @GetMapping("/hello") public String hello() { return "hello Spring security"; } }
00
Spring Security技术栈开发企业级认证与授权
Spring Security技术栈,REST风格开发常见接口,独立开发认证授权模块保证REST服务安全
2662 学习 · 1561 问题
相似问题