spring boot + spring security 启动错误 Looking for @ControllerAdvice

在运行spring security 源码spring-security-4.2.3.RELEASE\spring-security-4.2.3.RELEASE\samples\boot\helloworld 中的例子时,能正常显示login页面,但是把包的名字修改了之后,就不能跳到自定义的login页面了,而是跳到了spring security 默认的登录页面,原因是、
SpringBoot在写启动类的时候如果不使用@ComponentScan指明对象扫描范围,默认指扫描当前启动类所在的包里的对象,如果当前启动类没有包,则在启动时会报错:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package错误。因为启动类不能直接放在main/java文件夹下,必须要建一个包把它放进去或者使用@ComponentScan指明要扫描的包。代码示例如下:
@SpringBootApplication @ComponentScan (basePackageClasses=MytestApplication.class) public class MytestApplication { public static void main(String[] args){ SpringApplication.run(MytestApplication.class, args); }}

正常的log输出:2017-08-17 17:01:46.897 INFO 8572 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-08-17 17:01:46.897 INFO 8572 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-17 17:01:47.243 INFO 8572 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-08-17 17:01:47.250 INFO 8572 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-08-17 17:01:47.291 INFO 8572 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-08-17 17:01:47.292 INFO 8572 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-08-17 17:01:47.293 INFO 8572 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-08-17 17:01:47.316 INFO 8572 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-08-17 17:01:47.425 INFO 8572 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-08-17 17:01:47.620 INFO 8572 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'


2017-08-17 17:01:47.717 INFO 8572 --- [ main] o.s.s.samples.config.SecurityConfig : -----------WebSecurityConfigurerAdapter--------configureGlobal------- auth :org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder@dd2856e
2017-08-17 17:01:47.791 INFO 8572 --- [ main] o.s.s.samples.config.SecurityConfig : -----------WebSecurityConfigurerAdapter--------configure ---- http :org.springframework.security.config.annotation.web.builders.HttpSecurity@682af059
2017-08-17 17:01:47.865 INFO 8572 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@40c2ce52, org.springframework.security.web.context.SecurityContextPersistenceFilter@92d1782, org.springframework.security.web.header.HeaderWriterFilter@322ba549, org.springframework.security.web.csrf.CsrfFilter@558b4942, org.springframework.security.web.authentication.logout.LogoutFilter@13c8ac77, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@7e4579c7, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@72976b4, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@3a7e365, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@18a19e, org.springframework.security.web.session.SessionManagementFilter@5416f8db, org.springframework.security.web.access.ExceptionTranslationFilter@28a9494b, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@6870c3c2]
2017-08-17 17:01:48.026 INFO 8572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@39529185: startup date [Thu Aug 17 17:01:45 CST 2017]; root of context hierarchy
2017-08-17 17:01:48.067 INFO 8572 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/index]}" onto public java.lang.String org.springframework.security.samples.web.MainController.index()


main] o.s.s.sample.HelloWorldApplication : Starting HelloWorldApplication on DESKTOP-S96KA5C with PID 8900 (D:\idss\workspaces\workspace390\TestSecurity\target\classes started by gyx in D:\idss\workspaces\workspace390\TestSecurity)
2017-08-17 17:02:48.909 INFO 8900 --- [ main] o.s.s.sample.HelloWorldApplication : No active profile set, falling back to default profiles: default
2017-08-17 17:02:49.075 INFO 8900 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@39529185: startup date [Thu Aug 17 17:02:49 CST 2017]; root of context hierarchy
2017-08-17 17:02:49.427 WARN 8900 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[org.springframework.security.sample]' package. Please check your configuration.
2017-08-17 17:02:49.986 INFO 8900 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-08-17 17:02:49.992 INFO 8900 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-08-17 17:02:49.993 INFO 8900 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-08-17 17:02:50.065 INFO 8900 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-08-17 17:02:50.065 INFO 8900 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 993 ms
2017-08-17 17:02:50.208 INFO 8900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-08-17 17:02:50.208 INFO 8900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-08-17 17:02:50.208 INFO 8900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-08-17 17:02:50.208 INFO 8900 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-08-17 17:02:50.209 INFO 8900 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-08-17 17:02:50.209 INFO 8900 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-17 17:02:50.562 INFO 8900 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-08-17 17:02:50.570 INFO 8900 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-08-17 17:02:50.613 INFO 8900 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-08-17 17:02:50.614 INFO 8900 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-08-17 17:02:50.615 INFO 8900 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-08-17 17:02:50.645 INFO 8900 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-08-17 17:02:50.751 INFO 8900 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-08-17 17:02:51.003 INFO 8900 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'

2017-08-17 17:02:51.202 INFO 8900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@39529185: startup date [Thu Aug 17 17:02:49 CST 2017]; root of context hierarchy
2017-08-17 17:02:51.248 INFO 8900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-08-17 17:02:51.249 INFO 8900 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-08-17 17:02:51.268 INFO 8900 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-17 17:02:51.268 INFO 8900 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-17 17:02:51.294 INFO 8900 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-17 17:02:51.838 INFO 8900 --- [ main] b.a.s.AuthenticationManagerConfiguration :

Using default security password: 1705487c-27b5-4185-915a-d30110d4605f

2017-08-17 17:02:51.870 INFO 8900 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/css/**'], Ant [pattern='/js/**'], Ant [pattern='/images/**'], Ant [pattern='/webjars/**'], Ant [pattern='/**/favicon.ico'], Ant [pattern='/error']]], []
2017-08-17 17:02:51.918 INFO 8900 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6de004f1, org.springframework.security.web.context.SecurityContextPersistenceFilter@31efacad, org.springframework.security.web.header.HeaderWriterFilter@f723cdb, org.springframework.security.web.authentication.logout.LogoutFilter@1cd6b1bd, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@67e0fd6d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@38029686, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@fb5aeed, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@45d56062, org.springframework.security.web.session.SessionManagementFilter@3dc68586, org.springframework.security.web.access.ExceptionTranslationFilter@149274cb, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@168142da]
2017-08-17 17:02:52.046 INFO 8900 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-08-17 17:02:52.081 INFO 8900 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-08-17 17:02:52.084 INFO 8900 --- [ main] o.s.s.sample.HelloWorldApplication : Started HelloWorldApplication in 3.368 seconds (JVM running for 3.766)
2017-08-17 17:02:59.002 INFO 8900 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-08-17 17:02:59.002 INFO 8900 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-08-17 17:02:59.019 INFO 8900 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 16 ms

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值