在启动时查询注册表时的ComponentLookupError
发布时间:2020-12-14 04:20:43 所属栏目:Windows 来源:网络整理
导读:我正在构建一个应用程序,使用collective.lead(trunk)查询外部关系数据库中的某些数据.用户可以在自定义Plone控制面板工具中修改数据库连接设置(我按照Aspeli的Professional Plone Development书中的示例).以这种方式查询数据库设置. 我的产品base.zcml为数据
我正在构建一个应用程序,使用collective.lead(trunk)查询外部关系数据库中的某些数据.用户可以在自定义Plone控制面板工具中修改数据库连接设置(我按照Aspeli的Professional Plone Development书中的示例).以这种方式查询数据库设置.
我的产品base.zcml为数据库设置了一个实用程序: <include package="plone.app.registry" /> <include package="collective.lead" /> <i18n:registerTranslations directory="locales" /> <utility provides="collective.lead.interfaces.IDatabase" factory=".dbsettings.CalculatorDatabase" name="test.calc.db" /> dbsettings.py有: from zope.component import getUtility from plone.registry.interfaces import IRegistry class CalculatorDatabase(Database): @property def _url(self): registry = getUtility(IRegistry) settings = registry.forInterface(IDatabaseSettings) return URL( drivername=settings.drivername,username=settings.username,password=settings.password,host=settings.hostname,port=settings.port,database=settings.database,) 这会在运行时引发ComponentLookupError异常: File "/home/zope/envs/test-web/src/test.calc/test/calc/dbsettings.py",line 38,in _url registry = getUtility(IRegistry) File "/home/zope/envs/test-web/eggs/zope.component-3.7.1-py2.6.egg/zope/component/_api.py",line 171,in getUtility raise ComponentLookupError(interface,name) zope.configuration.config.ConfigurationExecutionError: <class 'zope.component.interfaces.ComponentLookupError'>: (<InterfaceClass plone.registry.interfaces.IRegistry>,'') in: File "/home/zope/envs/test-web/src/test.calc/test/calc/configure.zcml",line 26.2-30.6 <utility provides="collective.lead.interfaces.IDatabase" factory=".dbsettings.CalculatorDatabase" name="test.calc.db" /> 为什么在运行时找不到注册表?我究竟做错了什么? 谢谢.
史蒂夫提到的是问题的根源,因此我只会针对您无法进行异常处理的情况添加解决方法.在类似的场景中,我需要注册一个依赖于存储在注册表中的设置的实用程序.没有这些设置就无法注册该实用程序,所以我绝对希望事情按顺序发生.
解决方法是不在zcml中注册该实用程序,而是在以下订阅者中执行此操作: <subscriber for="Products.CMFPlone.interfaces.IPloneSiteRoot zope.app.publication.interfaces.IBeforeTraverseEvent" handler=".component.setupStuff" /> 这将保证setupStuff可以访问所有本地实用程序.另请注意,在查询实用程序是否已存在之后,setupStuff也会快速返回,因为订阅者将在每个请求上触发. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Windows XP上禁用IPv6地址自动配置
- Windows – LogonUser – >来自系统服务的CreateProcessAsU
- 如何在Qt的主窗口中打开一个新窗口?
- 每日扫盲二:xxx.dll文件的作用
- windows下mysql的安装到使用
- batch-file – 在遇到错误时停止执行批处理脚本
- dll中的c-std :: unique_ptr pimpl生成C4251与visual studi
- User mode and kernel mode (from MSDN)
- windows – 删除在同一进程中为独占访问而打开的文件
- windows – 有什么区别b / w MMC.exe和certmgr.msc
推荐文章
站长推荐
热点阅读