大约半天我试图找到一种方法将我在SpringSecurity上的实现迁移到OSGi(equinox)捆绑包 的上下文而不切换到SpringDM 。
目前我们有两个项目:
1。我有 Spring Security 的实现,它基于一些xml配置文件来处理身份验证和授权。
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功能的问题。
非常感谢
莫因
答案 0 :(得分:0)
你实际上并不需要Spring DM。它只是提供了OSGi和Spring之间的桥梁,还有一些细节,比如在OSGi环境中正确加载所有上下文文件。你也可以自己做,但你必须补偿类加载问题,这是你遇到的问题。
尝试此操作来修复类加载问题。
ApplicationContext ctx = new ClassPathXmlApplicationContext(myCtxPath)
{
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader)
{
super.initBeanDefinitionReader(reader);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.setBeanClassLoader(getClassLoader());
}
}
顺便说一下,你方法的第二行没有用处。