学习Spring Security的过程中遇到的问题汇总

首先分享两个学习Spring security的资源:http://www.mossle.com/docs/auth/html/index.html   (写成于2009年,较老,但是对于初学者还是很有帮助的)

http://www.iteye.com/blogs/subjects/spring_security  (完成于2014年-2016年间,且博主仍在更新,比较详细,适合有一定基础的朋友)

以上两个资源都是对Spring security成体系学习的好东西,分享给有意学习的朋友。


1、打出的错误信息如下:

严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4153)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
解决办法如下:项目的properties -> Deployment Assembly -> Add -> Java Build Path Entries -> next -> Maven Dependencies -> apply ,问题解决。

在解决问题的过程中发现有很多情况会导致如上问题,但是大多数情况下还是在build和deploy阶段没有正确的姿势导包。


2、错误信息如下:

严重: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd or spring-security-3.1.xsd schema with Spring Security 3.2. Please update your schema declarations to the 3.2 schema.
Offending resource: ServletContext resource [/WEB-INF/config/spring-security.xml]

我的spring-security.xml文件如下:


	
		
	
	
		
			
				
				
			
		
	
Spring 和 Spring Security版本信息如下:


		3.2.3.RELEASE
		4.0.4.RELEASE
	
stackoverflow 大神的说法如下:

The schema you are pointing to is spring-security-3.1.xsd, but the pom.xml declares spring-security-config-3.0.1.RELEASE. You should update your version of Spring Security or downgrade the version of the spring security namespace. Note when changing versions ensure that all Spring versions match and all Spring Security versions match (this includes transitive dependencies) otherwise you will get strange errors.

http://stackoverflow.com/questions/8916993/spring-security3-you-cannot-use-a-spring-security-2-0-xsd-schema


解决办法如下:在pom文件中,将spring-security版本降至至多3.2.0(不包含),或者提升spring-security 头部中的schema版本,但是没试过这个方法,反正我把spring security的版本降至3.1.3就可以了。


3、安装mysql后报错:ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061) 

进入计算机 右键 -> 管理 -> 服务和应用程序 -> 服务如果找不到mysql的话是没安装成功,可以试试mysql -install。如果找到mysql点击启动的时候报错如下:

Windows 无法启动MySQL服务(位于本地计算机上)。 错误2:系统找不到指定的文件. 

解决方案:打开regedit注册表,找到HEKY_LOCAL_MECHINE->SYSTEM->CurrentControlSet->servers->MYSQL->ImagePath 修改成mysql的安装目录。

4.报错信息如下:

严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.provisioning.JdbcUserDetailsManager#0': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/config/spring-security.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
解决办法:在pom.xml中加入如下信息:

		
			mysql
			mysql-connector-java
			5.1.30
		


你可能感兴趣的:(学习Spring Security的过程中遇到的问题汇总)