Spring OAuth2 实现与 InMemoryTokenStore bean 创建问题
Spring OAuth2 implementation with InMemoryTokenStore bean creation issue
我尝试使用此 blog
在我的项目中实施 Oauth2
我是 Spring 框架的新手,所以发生了诸如 ClassNotFoundException 之类的异常,尽管所有兼容的 类 都存在于正确的包下。
源码(maven项目)可以在github上看到
谢谢
错误开始于:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.HierarchicalJsr250Voter] for bean with name 'roleVoter' defined in class path resource [spring/security/security-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.HierarchicalJsr250Voter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.HierarchicalJsr250Voter] for bean with name 'roleVoter' defined in class path resource [spring/security/security-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.HierarchicalJsr250Voter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.filter.spring.SpringCrossOriginResourceSharingFilter] for bean with name 'corsFilter' defined in class path resource [spring/oauth/oauth2-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.filter.spring.SpringCrossOriginResourceSharingFilter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.OAuthRestEntryPoint] for bean with name 'oauthRestEntryPoint' defined in class path resource [spring/oauth/oauth2-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.OAuthRestEntryPoint
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
确保您 web.xml 正确初始化了 spring 上下文:
[更新]
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:app-config.xml
</param-value>
</context-param>
必须是直系子代。
然后,在您的应用程序配置中,您可以使用
扫描所有组件
<context:component-scan base-package="your.component.package.here"/>
然后导入所有 spring 配置文件
<import resource="classpath:your-resource.xml"/>
我还注意到 PropertiesPlaceholderConfigurer bean 没有正确配置,所以我不得不在我的一个 spring 配置文件上做这样的事情,它到处都在抛出异常,因为 spring 没有找到文件属性:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/application.properties"/>`</bean>`
有些 类 您实际上并不需要,但这取决于您。希望你能通过这些提示弄明白。
此致
异常的本质问题是构建路径问题。当我将 security-configuration.xml 文件内容移动到 business-config.xml 时,ide 警告我构建路径问题。所以我检查了项目的构建路径,maven dependecies 似乎没有被选中。我之前更改了 JDK 的版本,所以我认为这导致了未检查的情况。不幸的是,注意到花了一段时间...
我尝试使用此 blog
在我的项目中实施 Oauth2我是 Spring 框架的新手,所以发生了诸如 ClassNotFoundException 之类的异常,尽管所有兼容的 类 都存在于正确的包下。 源码(maven项目)可以在github上看到 谢谢
错误开始于:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.HierarchicalJsr250Voter] for bean with name 'roleVoter' defined in class path resource [spring/security/security-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.HierarchicalJsr250Voter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.HierarchicalJsr250Voter] for bean with name 'roleVoter' defined in class path resource [spring/security/security-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.HierarchicalJsr250Voter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.filter.spring.SpringCrossOriginResourceSharingFilter] for bean with name 'corsFilter' defined in class path resource [spring/oauth/oauth2-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.filter.spring.SpringCrossOriginResourceSharingFilter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.trafficalarm.rest.security.OAuthRestEntryPoint] for bean with name 'oauthRestEntryPoint' defined in class path resource [spring/oauth/oauth2-configuration.xml]; nested exception is java.lang.ClassNotFoundException: com.trafficalarm.rest.security.OAuthRestEntryPoint
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
确保您 web.xml 正确初始化了 spring 上下文: [更新]
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:app-config.xml
</param-value>
</context-param>
必须是直系子代。 然后,在您的应用程序配置中,您可以使用
扫描所有组件<context:component-scan base-package="your.component.package.here"/>
然后导入所有 spring 配置文件
<import resource="classpath:your-resource.xml"/>
我还注意到 PropertiesPlaceholderConfigurer bean 没有正确配置,所以我不得不在我的一个 spring 配置文件上做这样的事情,它到处都在抛出异常,因为 spring 没有找到文件属性:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/application.properties"/>`</bean>`
有些 类 您实际上并不需要,但这取决于您。希望你能通过这些提示弄明白。
此致
异常的本质问题是构建路径问题。当我将 security-configuration.xml 文件内容移动到 business-config.xml 时,ide 警告我构建路径问题。所以我检查了项目的构建路径,maven dependecies 似乎没有被选中。我之前更改了 JDK 的版本,所以我认为这导致了未检查的情况。不幸的是,注意到花了一段时间...