Restore support for empty persistence unit with fat jars

Due to the layout format change in 1.4, Spring Framework is no longer
able to compute a default persistence unit root URL. If a Spring Boot 1.4
application has JPA but does not have any entity, the application started
from a fat jar now fails with a quite cryptic exception.

This commit introduces `ApplicationInfo` as a general replacement for
the `ApplicationArguments` and `Banner` singleton beans that
`SpringApplication` registers on startup. `ApplicationInfo` also defines
the detected "main" `Class` that can be used to compute a last resort
URL that makes sense.

If such bean is available, `EntityManagerFactoryBuilder` now sets the
default persistence unit root location, preventing Spring Framework to
attempt to resolve an unknown location. Note that in our case the
persistence unit root location is actually useless: given the way the
persistence unit is created, nothing actually uses it but Hibernate, as a
compliant JPA provider, has to make sure this setting is set to a valid
URL nevertheless.

Closes gh-6635
This commit is contained in:
Stephane Nicoll
2016-08-23 08:28:55 +02:00
parent 86757efcdf
commit b9104c9337
8 changed files with 145 additions and 6 deletions

View File

@@ -11,9 +11,9 @@ welcome = { ->
// Try to print using the banner interface
if (beanFactory != null) {
try {
def banner = beanFactory.getBean("springBootBanner")
def appInfo = beanFactory.getBean("springApplicationInfo")
def out = new java.io.ByteArrayOutputStream()
banner.printBanner(environment, null, new java.io.PrintStream(out))
appInfo.banner.printBanner(environment, null, new java.io.PrintStream(out))
return out.toString()
} catch (Exception ex) {
// Ignore