I have inherited model classes:
public class AbstractUser extends Model
and
public class User extends AbstractUser
I'm attempting to extend from a base project into several children project. The Users in each project will have many similar base attributes, but only one or two custom attributes. I'm hoping I can extend in such a way, so when bugs/updates come in regarding base classes, I only have to make updates to the base class. Alternatively, I'll have to have duplicated code across several projects. I'm planning on extending this to other classes as well. No prob doing this with the app.controllers.
My base class of course fires up just fine. In my extended classes, I'm executing:
mvn org.javalite:activejdbc-instrumentation:1.4.12:instrument
... then moving the exploded WAR into my Jetty webapp. Whenever I hit the extended model, I get the following stack trace:
org.javalite.activejdbc.InitException: failed to determine Model class name, are you sure models have been instrumented?
at org.javalite.activejdbc.Model.modelClass(Model.java:2726)
at org.javalite.activejdbc.Model.findAll(Model.java:2349)
at com.nearstar.model.ApplicationProperties.getInstance(ApplicationProperties.java:41)
at app.controllers.LoginController.login(LoginController.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.javalite.activeweb.ControllerRunner.executeAction(ControllerRunner.java:289)
at org.javalite.activeweb.ControllerRunner.run(ControllerRunner.java:65)
at org.javalite.activeweb.RequestDispatcher.doFilter(RequestDispatcher.java:202)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1676)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:524)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:745)
Is it possible to extend instrumented models in this manner?
答案 0 :(得分:1)
首先,如果您收到消息are you sure models have been instrumented?
,则表示您的模型尚未进行检测。也许您的IDE覆盖了类文件或脚本无法正常工作,但这种情况会导致此消息。
其次,ActiveJDBC中的继承确实有一些限制。请查看此文档:http://javalite.io/inheritance。
你想做什么似乎是可能的。我没有看到太多问题。但是,在我的项目中,我通常只有一个common
Maven模块,它包含所有模型,实用程序类和服务。然后我使用Maven依赖机制将common
拉入其他项目。多年来,这种方法对许多商业项目都非常有效。
第三,包app.controllers
仅对于......控制器是必需的:)您的模型可以放在任何包和模块中。只要模型已经过检测,并且可以位于classspath上,它们就可以按预期工作。