大约有半天的时间,我试图找到一种方法将我在 SpringSecurity 上的实现迁移到 OSGi(equinox) 包的上下文而不切换到 SpringDM。
目前我们有两个项目:
1.我有一个基于一些xml配置文件的Spring Security的实现来处理认证和授权。
2.另一方面,我们有一个庞大的OGSi 捆绑项目结构,其中包含大约 200 个捆绑包,需要与安全捆绑包(如上所述的那个)集成
作为创建mySpringBasedSecurityBundle
的第一步,我需要在加载 mySecurityBundle 后运行此方法以访问位于以下位置的安全配置 xml 文件:com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml
,它为我准备了Spring-DataSource。 xml和Spring-Security.xml如下:
private void loadApplicationContext()
{
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
new ThreadLocal<Object>();
setApplicationContext(new ClassPathXmlApplicationContext(SPRING_CONTEXT_ADDRESS));
}
但不幸的是,发生了这个异常:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.myComp.backend.appsecurity.spring.appSecurityManager.loadApplicationContext(appSecurityManager.java:233)
at com.myComp.backend.appsecurity.spring.appSecurityManager.internalInitialize(appSecurityManager.java:106)
at com.myComp.BaseModuleManager.initialize(BaseModuleManager.java:511)
at com.myComp.BaseModuleManager.initialize(BaseModuleManager.java:1)
at com.myComp.backend.BaseBackendManager.initializeSubBackendManagers(BaseBackendManager.java:643)
at com.myComp.backend.BaseBackendManager.prepareSubBackendManagers(BaseBackendManager.java:885)
at com.myComp.backend.BackendManager.internalStart(BackendManager.java:127)
at com.myComp.BaseModuleManager.start(BaseModuleManager.java:574)
at com.myComp.BaseModuleManager.start(BaseModuleManager.java:1)
at com.myComp.application.BaseApplicationStub.startBackendManager(BaseApplicationStub.java:2407)
at com.myComp.Application.frameworkEvent(Application.java:72)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:874)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)Caused by: java.io.FileNotFoundException: class path resource [com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
.. 26 more
尽管我在网上搜索,对于这个问题的唯一建议是在 SpringDM 上的应用程序,但我们的 ProjectManager 切换到 SpringDM 是不可接受的,老实说我对 SpringDM 不了解。
请您使用 Spring Core 功能帮助我解决此问题。
非常感谢
Moein