0

我尝试使用此博客将 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$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
4

2 回答 2

1

确保您的 web.xml 确实正确初始化了 spring 上下文:[更新]

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:app-config.xml
    </param-value>
</context-param>

必须是直系子女。然后,在您的 app-config 中,您可以使用扫描所有组件

<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>`

有些课程您实际上并不需要,但这取决于您。希望你能通过这些提示弄清楚。

问候

于 2015-03-26T00:16:39.940 回答
0

关于异常的基本问题是构建路径问题。当我将 security-configuration.xml 文件内容移动到 business-config.xml 时,ide 警告我构建路径问题。所以我检查了项目的构建路径,maven依赖似乎没有被选中。我之前更改了 JDK 的版本,所以我认为这导致了未经检查的情况。不幸的是,注意到需要一段时间......

于 2015-03-30T12:50:10.653 回答