Recently, the basic application platform has been transformed to expand a micro service development model. Transform the basic application platform from the traditional development mode to adapt to the micro service development mode. It is worth noting that the basic application platform here does not adopt the mainstream spring system, but the IOC framework written from servlet, which realizes the dependency injection function similar to spring. It can be said to be a simplified version of spring, castrating the functions that N can't use, and the operation efficiency is very high.
-----------------------------------Gorgeous dividing line----------------------------------------------
This is where I begin to describe my problems.
In the micro service iport project, the source code only includes the Java addition, deletion, modification and query logic code of the iport module and the htm page of the iport module. The basic pages that the htm page of the iport module depends on (for example, jquery.js, layui.js, css, etc. are all from xxxbase-0.4.1-theme-zone.jar). xxxbase-0.4.1.theme-zone.jar is completely packaged by API Gateway project through maven. This jar package contains a directory structure similar to this:
In the iport project, the page code includes the introduction of freemaker:
Where:/ stage/PageFamily. The ftl template page is in xxxbase-0.4.1-theme-zone Jar. The ftl loading logic of the framework xxbase has been changed to give priority to loading the files in the WebRoot directory. If it cannot be found, look in the jar package.
After running, the error contents are as follows:
Caused by: java.lang.RuntimeException: freemarker.core._MiscTemplateException: Template inclusion failed (for parameter value "../stage/PageFamily.ftl"): Template not found for name "device/../stage/PageFamily.ftl" (normalized: "stage/PageFamily.ftl"). The name was interpreted by this TemplateLoader: ClassTemplateLoader(resourceLoaderClass=net.routeyo.se.web.render.FreeMarkerRender, basePackagePath="/net/routeyo/"). ---- FTL stack trace ("~" means nesting-related): - Failed at: #include "../stage/PageFamily.ftl" [in template "device/apiUserPortListPage.htm" at line 1, column 1] ---- at net.routeyo.se.web.render.FreeMarkerRender.render(FreeMarkerRender.java:135) at net.routeyo.se.web.RequestHandler.render(RequestHandler.java:312) at net.routeyo.se.web.RequestHandler.renderTemplate(RequestHandler.java:246) at net.routeyo.tags.device.ApiUserPortAction.toApiUserPortPage(ApiUserPortAction.java:96) ... 37 more Caused by: freemarker.core._MiscTemplateException: Template inclusion failed (for parameter value "../stage/PageFamily.ftl"): Template not found for name "device/../stage/PageFamily.ftl" (normalized: "stage/PageFamily.ftl"). The name was interpreted by this TemplateLoader: ClassTemplateLoader(resourceLoaderClass=net.routeyo.se.web.render.FreeMarkerRender, basePackagePath="/net/routeyo/"). ---- FTL stack trace ("~" means nesting-related): - Failed at: #include "../stage/PageFamily.ftl" [in template "device/apiUserPortListPage.htm" at line 1, column 1] ---- at freemarker.core.Include.accept(Include.java:160) at freemarker.core.Environment.visit(Environment.java:324) at freemarker.core.MixedContent.accept(MixedContent.java:54) at freemarker.core.Environment.visit(Environment.java:324) at freemarker.core.Environment.process(Environment.java:302) at freemarker.template.Template.process(Template.java:325) at net.routeyo.se.web.render.FreeMarkerRender.render(FreeMarkerRender.java:126) ... 40 more Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "device/../stage/PageFamily.ftl" (normalized: "stage/PageFamily.ftl"). The name was interpreted by this TemplateLoader: ClassTemplateLoader(resourceLoaderClass=net.routeyo.se.web.render.FreeMarkerRender, basePackagePath="/net/routeyo/"). at freemarker.template.Configuration.getTemplate(Configuration.java:1833) at freemarker.core.Environment.getTemplateForInclusion(Environment.java:2044) at freemarker.core.Include.accept(Include.java:158) ... 46 more
Analysis from the log: the path should not be found correctly. So I began to find the reason from the FreeMarker source code.
1. Enter include Java: 158 (you can directly click Include.java:158 on Eclipse to locate it), and find the path device // stage/PageFamily.ftl is a little strange, so I guess whether freemaker doesn't know such a path and should change it to stage/pagefamily FTL?
2. Enter configuration Java: 1833. It is found that ftl passes through cache For getTemplate processing, the path of ftl should be processed in getTemplate.
3. Enter cache View in getTemplate: found through templateNameFormat Normalizeabsolutename (name). So find the implementation class of templateNameFormat.
4. Find the implementation of templateNameFormat and find two implementation classes. Default020300 is used in the program. So go to the implementation class of default020300 to see the code.
The following figure proves that it is implemented with the templateNameFormat of Default020300.
5. Go to the implementation class of Default020300 and look at the code. It is found that the path has indeed been handled by FreeMarker, and FM has set device // stage/PageFamily. The FTL path is processed as stage / pagefamily FTL, so there is no problem that freemaker doesn't know strange paths.
Since it is not a path problem (the path is correct), it may be that the main function does not set xxxbase-0.4.1-theme-zone The jar package is added to the running environment, that is, the - cp parameter does not take xxxbase-0.4.1-theme-zone jar. So I'm ready to take a look at the vm variable started by the main function with jconsole.
6. Use jconsole to view the vm variables started by the main function. Enter jconsole on the console, find the corresponding process, and double-click it.
7. Enter the jconsole main interface and find the VM summary. There are too many VM parameters to see clearly. Copy and paste them into Notepad for processing. It was found that xxxbase-0.4.1-theme-zone Add jar to VM parameters.
VM parameters after processing:
8. In Eclipse, manually set xxxbase - 0.4.1 - Theme - zone Add jar to the dependent environment. Restart main, find the problem and solve it. The ftl file path can be found.
9. The reason is that maven in Eclipse relies on the source code and directly relies on the source code. However, the api Gateway project does not mutate the page into classes (the page is packaged as a jar package only when maven is installed)
10. Summary: when building the development architecture, you should pay attention to the dependency of maven and check the vm parameters frequently. When you can't find the reason from the log, turn to the source code to check. You should make a bold guess and verify it carefully.