RegistryBuilder 未为一个项目添加 Tapestry AppModule,但在另一个项目中工作正常

Tapestry AppModule not added by RegistryBuilder for one project, works fine for another

我正在使用 Eclipse Mars、Tomcat7、Java8、Sysdeo DevLoader,我按照 a Tynamo tutorial 配置 tomcat 插件。

我有两个几乎相同的 Tapestry 项目。一个应用程序运行良好,另一个应用程序无法提供任何页面,抛出:

SEVERE: Servlet.service() for servlet [default] in context with path [/admin] threw exception
java.lang.RuntimeException: Exception constructing service 'WebSecurityManager': Error invoking constructor public org.tynamo.security.services.TapestryRealmSecurityManager(org.tynamo.security.Authenticator,org.apache.shiro.mgt.SubjectFactory,org.apache.shiro.mgt.RememberMeManager,java.util.Collection): Realms collection argument cannot be empty.
    at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:75)
...
Caused by: java.lang.IllegalArgumentException: Realms collection argument cannot be empty.
at org.apache.shiro.mgt.RealmSecurityManager.setRealms(RealmSecurityManager.java:78)
at org.tynamo.security.services.TapestryRealmSecurityManager.<init>(TapestryRealmSecurityManager.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.tapestry5.ioc.internal.util.ConstructorInvoker.invoke(ConstructorInvoker.java:48)
... 50 more

问题似乎源于我的 AppModule.addRealms 在安全管理员尝试获取 Subject 之前未在问题应用程序中被调用。事实上,其中一个应用程序似乎享受 'Tapestry treatment' 而另一个不喜欢。这是有效的:

Nov 05, 2015 11:45:53 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/bray.xml
Nov 05, 2015 11:45:53 AM org.apache.catalina.core.StandardContext setPath
WARNING: A context path must either be an empty string or start with a '/'. The path [bray] does not meet these criteria and has been changed to [/bray]
Nov 05, 2015 11:45:53 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Context/Loader} Setting property 'debug' to '1' did not find a matching property.
Nov 05, 2015 11:45:53 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
[DevLoader] Starting DevLoader
[DevLoader] projectdir=/home/claude/git/bray/src/main/webapp
[DevLoader] added file:/home/claude/git/bray/target/classes/
...
[INFO] ioc.RegistryBuilder Adding module definition for class com.mydomain.services.AppModule
[INFO] TapestryModule.ComponentClassResolver Available pages (16):
              (blank): com.mydomain.pages.Index
                About: com.mydomain.pages.About

然后我看到来自 Tapestry 的 "hello" 和我的另一个项目 (admin) 出现了:

...
Application 'app' (version 1.0-SNAPSHOT) startup time: 172 ms to build IoC Registry, 541 ms overall.

 ______                  __             ____
/_  __/__ ____  ___ ___ / /_______ __  / __/
 / / / _ `/ _ \/ -_|_-</ __/ __/ // / /__ \ 
/_/  \_,_/ .__/\__/___/\__/_/  \_, / /____/
        /_/                   /___/  5.3.8 (development mode)


Nov 05, 2015 11:45:58 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/admin.xml
Nov 05, 2015 11:45:58 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Context/Loader} Setting property 'debug' to '1' did not find a matching property.
Nov 05, 2015 11:45:58 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
[DevLoader] Starting DevLoader
[DevLoader] projectdir=/home/claude/git/tegu/admin/src/main/webapp
...
Nov 05, 2015 11:45:58 AM org.apache.catalina.deploy.WebXml setVersion
WARNING: Unknown version string [3.1]. Default version will be used.
log4j:WARN No appenders could be found for logger (org.apache.tapestry5.ioc.RegistryBuilder).
log4j:WARN Please initialize the log4j system properly.
Nov 05, 2015 11:46:02 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/manager.xml
Nov 05, 2015 11:46:02 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/docs.xml
Nov 05, 2015 11:46:02 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/host-manager.xml
Nov 05, 2015 11:46:02 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/examples.xml

我希望在我的 admin.xml 描述符部署后看到这样的东西:

[INFO] ioc.RegistryBuilder Adding module definition for class com.myotherdomain.admin.services.AppModule
[INFO] TapestryModule.ComponentClassResolver Available pages (16):

...取而代之的是沉默。我看不出这两个应用程序有什么不同会导致一个工作而另一个失败。我应该看哪里?

DevLoader 类路径错误。修复一切。

DevLoader Classpath 不包括路径 /myapp/target/classes —— 而这正是我的应用程序的 AppModule 所在的位置(准确地说是 /myapp/target/classes/com/mydomain/myapp/services/AppModule.class)。这可以在 Project -> Properties -> Tomcat 中修复并选中正确路径的复选框。错误的配置也可以在项目 WEB-INF 旁边的名为 .#webclasspath 的文件中看到,该文件拼出了完整的路径(相对路径显示在配置页面中)。修复设置后,启动 Tomcat 并且 .#webclasspath 应该会自动更新。