2013-10-23 56 views
0

我想在解決this錯誤(這是一個版本不匹配問題)後集成JSF2和spring安全性,現在我得到一個新的錯誤。這個配置有什麼問題?結合Spring安全性和JSF 2:在ServletContext資源中定義的名稱爲'dataSource'的bean時出錯

我已閱讀thisthis和更多一些,但它們都沒有解決我的問題

我使用:

<properties> 
    <hibernate.version>4.2.6.Final</hibernate.version> 
    <log4j.version>1.2.17</log4j.version> 
    <slf4j.version>1.7.5</slf4j.version> 
    <spring.version>3.2.4.RELEASE</spring.version> 
    <springsecurity.version>3.1.4.RELEASE</springsecurity.version> 
    <jetty.version>8.1.7.v20120910</jetty.version> 
</properties> 

彈簧database.xml:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql://localhost:3306/azraspina" /> 
     <property name="username" value="root" /> 
    </bean> 

</beans> 

和這是spring-security.xml:

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

    <http auto-config="false" entry-point-ref="LoginUrlAuthenticationEntryPoint "> 
     <intercept-url pattern="/**" access="ROLE_USER" /> 
     <logout logout-success-url="/index.xhtml" /> 
     <custom-filter position="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter" /> 
    </http> 

    <http pattern="/css/**" security="none" /> 
    <http pattern="/images/**" security="none" /> 
    <http pattern="/js/**" security="none" /> 
    <http pattern="/resources/**" security="none" /> 


    <beans:bean id="authenticationProcessingFilter" 
     class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
     <beans:property name="authenticationManager" ref="authenticationManager" /> 
     <beans:property name="authenticationFailureHandler" 
      ref="failureHandler" /> 
     <beans:property name="authenticationSuccessHandler" 
      ref="successHandler" /> 
    </beans:bean> 

    <beans:bean id="successHandler" 
     class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
     <beans:property name="defaultTargetUrl" value="/index.xhtml" /> 
    </beans:bean> 

    <beans:bean id="failureHandler" 
     class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
     <beans:property name="defaultFailureUrl" value="/index.xhtml" /> 
    </beans:bean> 

    <beans:bean id="LoginUrlAuthenticationEntryPoint" 
     class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 
     <beans:property name="loginFormUrl" value="/index.xhtml" /> 
     <beans:property name="forceHttps" value="false" /> 
    </beans:bean> 

    <authentication-manager alias="authenticationManager"> 
     <authentication-provider> 
      <jdbc-user-service data-source-ref="dataSource" 
       users-by-username-query=" 
        select username,password, enabled 
        from users where username=?" 
       authorities-by-username-query=" 
        select u.username, r.authority from users u, roles r, user_roles ur 
        where u.user_id = ur.user_id and r.role_id = ur.role_id and u.username =? " /> 
     </authentication-provider> 
    </authentication-manager> 


</beans:beans> 
棧跟蹤的

和部分:

ct 23, 2013 3:24:59 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/spring-database.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchFieldError: NULL 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 
Caused by: java.lang.NoSuchFieldError: NULL 
    at org.springframework.expression.TypedValue.<clinit>(TypedValue.java:32) 
    at org.springframework.expression.spel.support.StandardEvaluationContext.setRootObject(StandardEvaluationContext.java:88) 
    at org.springframework.expression.spel.support.StandardEvaluationContext.<init>(StandardEvaluationContext.java:74) 
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:124) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1312) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:211) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:183) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    ... 20 more 

回答

0

解決。

的訣竅是添加此依賴關係的pom.xml

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-expression</artifactId> 
    <version>3.2.4.RELEASE</version> 
</dependency> 

現在似乎很容易:d

相關問題