如何解决无法让Jetty扫描胖子罐中的带注释的类
我有一个带有嵌入式码头服务器的应用程序,我正在这样启动(放置在main()中,并使用eclipse启动)
Server server = new Server(port);
WebAppContext context = new WebAppContext();
context.setResourceBase("web/");
context.setDescriptor("web/WEB-INF/web.xml");
context.setConfigurations(new Configuration[]{
new AnnotationConfiguration(),new WebXmlConfiguration(),new WebInfConfiguration(),new TagLibConfiguration(),new PlusConfiguration(),new MetaInfConfiguration(),new FragmentConfiguration(),new EnvConfiguration()});
context.setContextPath("/");
context.setParentLoaderPriority(true);
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/classes/.*");
URL classes = Main.class
.getProtectionDomain()
.getCodeSource()
.getLocation();
URL url = Main.class.getResource("/packageX/packageY/");
context.getMetaData().setWebInfClassesDirs(Arrays.asList(Resource.newResource(classes)));
//If i replace classes with url it can't find annotated filters or listeners.
//context.getMetaData().setWebInfClassesDirs(Arrays.asList(Resource.newResource(url)));
server.setHandler(context);
server.start();
server.join();
上面的代码运行正常,但是它扫描了我的胖子罐中的所有软件包,这很耗时。因此,我想通过提供用于搜索的包路径来缩小搜索空间,但此后它找不到任何带注释的类。我在这里做什么错了?
解决方法
这两个属性...
-
org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern
用于控制扫描哪些容器JAR。 -
org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern
用于控制要扫描哪些WebApp JAR。
..仅适用于JAR级别。拥有真正的uber-jar kinda会使这两个配置都没有意义。
您是否考虑过将uber-jar变成一场实战?并更好地将容器部分和Webapp部分分开?
请参阅:https://github.com/jetty-project/embedded-jetty-live-war
您还可以在构建时对字节码/注释可扫描组件进行预先计算,并通过特殊的WebAppContext
组件加载QuickStartWebApp
,而在嵌入时完全跳过注释扫描步骤。 / p>
请参阅:https://www.eclipse.org/jetty/documentation/current/quickstart-webapp.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。