2017-05-17 22 views
1

私はスプリングアプリケーションを開発しようとしています。私は春のセキュリティを設定している間、いくつかの問題が生じています。私はそれを多くの方法で処理しようとしましたが、失敗しました。私にこれを解決してください。前もって感謝します。スプリングセキュリティ設定を設定中にエラーが発生しました

のpom.xml

<!-- Security dependency starts --> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-web</artifactId> 
     <version>4.2.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>4.2.2.RELEASE</version> 
    </dependency>  
    <!-- Security dependency ends --> 

web.xmlの

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

applicationContex.xml

ここで私は

のsecurity.xmlファイルをインポートします
<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:cache="http://www.springframework.org/schema/cache" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 

    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.springframework.org/schema/cache 
     http://www.springframework.org/schema/cache/spring-cache-3.2.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/jdbc 
     http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
     http://www.springframework.org/schema/data/jpa 
     http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"> 


    //some stuffs 
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     //some stuffs 
    </bean> 

    <tx:annotation-driven transaction-manager="transactionManager"/> 

    <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> 
     <property name="dataSource" ref="dataSource"/> 
    </bean> 

    <jpa:repositories base-package="proBlogAdvisor.repository"/>   

    //imorting security.xml file here 
    <import resource="security.xml" /> 
</beans> 

のsecurity.xml

<b:beans xmlns="http://www.springframework.org/schema/security" 
     xmlns:b="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.xsd 
     http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> 


    <http auto-config='true'> 
     <intercept-url pattern="/users**" access="ROLE_USER" /> 
    </http> 

    <authentication-manager> 
     <authentication-provider> 
      <!-- password-encoder hash="sha"/--> 
      <user-service> 
       <user name="admin" password="admin" 
       authorities="ROLE_USER, ROLE_ADMIN" /> 
      </user-service> 
     </authentication-provider> 
    </authentication-manager> 
</b:beans> 

エラー

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [/security.xml] 
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security] 
Offending resource: ServletContext resource [/WEB-INF/security.xml] 

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) 
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) 
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:259) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:184) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:169) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:748) 
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security] 
Offending resource: ServletContext resource [/WEB-INF/security.xml] 

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) 
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) 
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:301) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1408) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:172) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:243) 
    ... 32 more 

May 17, 2017 10:55:33 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file 
May 17, 2017 10:55:33 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Context [/proBlog] startup failed due to previous errors 
May 17, 2017 10:55:33 PM org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
May 17, 2017 10:55:33 PM org.apache.catalina.core.StandardContext listenerStop 
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener 
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170) 
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033) 
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1009) 
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961) 
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:583) 
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:116) 
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4792) 
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5429) 
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:748) 
+0

http://stackoverflow.com/questions/7188719/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace-http-www-sp – StanislavL

答えて

1

ダウンロード

  1. 春-AOP-4.3.8.RELEASE.jar
  2. 秒プリング・セキュリティ設定-4.2.2.RELEASE.jar
  3. 春・セキュリティ・コア4.2.2.RELEASE.jar
  4. 春 - セキュリティのWeb 4.2.2.RELEASE.jar
外部から

jars。既にpom.xmlファイルに依存関係を追加していても心配しないでください。ダウンロードしてコピーし、WEB_INF/libフォルダに貼り付けてください。それはうまく動作します。

+0

ほとんどの場合、すべてのjarファイルlibフォルダに、Movenプロジェクトが自動的に添付します – Nishakar

関連する問題