Troubleshooting Spring Boot Jar Loading Issues
Have you encountered the problem of starting a new Spring Boot archive?
In general, innovation in this direction is not the first, there are no special standards. Therefore, many people rake problems and solve them on forums and stack overflows.
If you also encounter a problem, I will help you solve it. In this case, read on.
, BootJar . , .
. — JSP . JSP? , - , , .
( ):
/src/main/ java/ resources/ static/ some.html public/ webapp/ WEB-INF/jsp index.jsp
BootJar / BootWar, jsp BootJar . BootWar. , . , — , , , . BootRun , .
, : , .
, . BootJar. , … ! , 302 + 404 ( ). .
— , , , webjars. ???
. jsp BootJar, BootWar. … . , .
, . BootJar — . .
: Spring Boot , . — . ! .
. — BootJar (webjars), , , , , ! , .
— - static/, public/. , . jsp . , . , ( ), jsp . jsp ,
spring.resources.static-locations
.
, , , . , ( webapp/), , , — META-INF/resources, . BootJar. .
? -, -, , . — . , . , .
-? -, , , -, . , . , : — , , .
. . , , classpath.
, . ?
.
- spring- . , , , jsp .
- . : spring-, , — , , . , .
- — BootJar.
sourceSets {
jsp {
resources.source(sourceSets.main.resources);
resources.srcDirs += ['src/main/webapp'];
}
jmh {
.. ..
}
}
task jsp(type: Jar, description: 'JSP Packaging') {
archiveBaseName = 'jsp'
group = "build"
def art = sourceSets.jsp.output
from(art) {
exclude('META-INF')
into('META-INF/resources/')
}
from(art) {
include('META-INF/*')
into('/')
}
dependsOn(processJspResources)
}
processJspResources , . :
bootJar {
dependsOn(jsp)
bootInf.with {
from(jsp.archiveFile) {
include('**/*.jar')
}
into('lib/')
}
}
I could not find how to add it in another way (direct) - it is impossible to connect the jspImplementation config of the project itself depending on the dependencies, but I would like to. But if we still take it from another module, then we still do this:
artifacts { jspImplementation jsp }
That's it, now we have a resource lib, which, according to all standards, the tomkat must load, and it loads. Run it like BootJar.