Fix #1142 - Upgrade Spring Boot to latest version

This commit is contained in:
James Agnew 2018-12-23 13:10:03 -05:00
parent a0cb7edd08
commit 9d3904ef3e
7 changed files with 161 additions and 164 deletions

View File

@ -28,7 +28,9 @@ import ca.uhn.fhir.rest.server.IPagingProvider;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service // Note: this class is not annotated with @Service because we want to
// explicitly define it in BaseConfig.java. This is done so that
// implementors can override if they want to.
public class DatabaseBackedPagingProvider extends BasePagingProvider implements IPagingProvider { public class DatabaseBackedPagingProvider extends BasePagingProvider implements IPagingProvider {
@Autowired @Autowired

View File

@ -31,6 +31,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.provider.BaseJpaProvider; import ca.uhn.fhir.jpa.provider.BaseJpaProvider;
import ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider; import ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider;
import ca.uhn.fhir.model.dstu2.resource.AuditEvent;
import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory; import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory;
import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory;
import ca.uhn.fhir.rest.client.api.IClientInterceptor; import ca.uhn.fhir.rest.client.api.IClientInterceptor;
@ -46,6 +47,7 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.*; import org.springframework.boot.autoconfigure.condition.*;
@ -69,6 +71,7 @@ import org.springframework.util.CollectionUtils;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for HAPI FHIR. * {@link EnableAutoConfiguration Auto-configuration} for HAPI FHIR.
@ -164,26 +167,11 @@ public class FhirAutoConfiguration {
@ConditionalOnBean(DataSource.class) @ConditionalOnBean(DataSource.class)
@EnableConfigurationProperties(FhirProperties.class) @EnableConfigurationProperties(FhirProperties.class)
static class FhirJpaServerConfiguration { static class FhirJpaServerConfiguration {
@Autowired
@Bean private ScheduledExecutorService myScheduledExecutorService;
@ConditionalOnMissingBean
public ScheduledExecutorFactoryBean scheduledExecutorService() {
ScheduledExecutorFactoryBean b = new ScheduledExecutorFactoryBean();
b.setPoolSize(5);
return b;
}
@Bean(name=BaseConfig.TASK_EXECUTOR_NAME)
public AsyncTaskExecutor taskScheduler() {
ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler();
retVal.setConcurrentExecutor(scheduledExecutorService().getObject());
retVal.setScheduledExecutor(scheduledExecutorService().getObject());
return retVal;
}
@Configuration @Configuration
@EntityScan(basePackages = {"ca.uhn.fhir.jpa.entity", "ca.uhn.fhir.jpa.model.entity"}) @EntityScan(basePackages = {"ca.uhn.fhir.jpa.entity", "ca.uhn.fhir.jpa.model.entity"})
@EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data")
static class FhirJpaDaoConfiguration { static class FhirJpaDaoConfiguration {
@Bean @Bean

View File

@ -1,8 +1,5 @@
package ca.uhn.fhir.spring.boot.autoconfigure; package ca.uhn.fhir.spring.boot.autoconfigure;
import java.net.URL;
import java.net.URLClassLoader;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
@ -14,18 +11,19 @@ import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration.FhirJpaServerConfiguration.Dstu3; import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration.FhirJpaServerConfiguration.Dstu3;
import org.assertj.core.util.Arrays; import org.assertj.core.util.Arrays;
import org.junit.After; import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.mock.env.MockEnvironment;
import java.net.URL;
import java.net.URLClassLoader;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -36,149 +34,157 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class FhirAutoConfigurationTest { public class FhirAutoConfigurationTest {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public final ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context;
@After @After
public void close() { public void close() {
if (this.context != null) { if (this.context != null) {
this.context.close(); this.context.close();
} }
} }
@Test @Test
public void withFhirContext() throws Exception { public void withFhirContext() throws Exception {
load(); load();
assertThat(this.context.getBeansOfType(FhirContext.class)).hasSize(1); assertThat(this.context.getBeansOfType(FhirContext.class)).hasSize(1);
} }
@Test @Test
public void withFhirVersion() throws Exception { public void withFhirVersion() throws Exception {
load(Arrays.array(EmbeddedDataSourceConfiguration.class, load(Arrays.array(EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
FhirAutoConfiguration.class), FhirAutoConfiguration.class),
"hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles",
"spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory");
assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.DSTU3.getVersionImplementation()); assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.DSTU3.getVersionImplementation());
load(Arrays.array(EmbeddedDataSourceConfiguration.class, load(Arrays.array(EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
FhirAutoConfiguration.class), FhirAutoConfiguration.class),
"hapi.fhir.version:R4", "hapi.fhir.version:R4",
"spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles",
"spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory");
assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.R4.getVersionImplementation()); assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.R4.getVersionImplementation());
} }
@Test @Test
public void withRestfulServer() { public void withRestfulServer() {
load("hapi.fhir.server.path:/hapi-fhir/*"); load("hapi.fhir.server.path:/hapi-fhir/*");
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1); assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
assertThat(this.context.getBeansOfType(RestfulServer.class)).hasSize(1); assertThat(this.context.getBeansOfType(RestfulServer.class)).hasSize(1);
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings()).contains("/hapi-fhir/*"); assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings()).contains("/hapi-fhir/*");
} }
@Test @Test
public void withJpaServer() { public void withJpaServer() {
load( load(
Arrays.array( Arrays.array(
EmbeddedDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
FhirAutoConfiguration.class), FhirAutoConfiguration.class),
"hapi.fhir.version:DSTU3", "hapi.fhir.version:DSTU3",
"spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles",
"spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory");
assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1); assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1); assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1);
} }
@Test @Test
public void withNoValidation() { public void withNoValidation() {
load("hapi.fhir.validation.enabled:false"); load("hapi.fhir.validation.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class); this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(RequestValidatingInterceptor.class); this.context.getBean(RequestValidatingInterceptor.class);
} }
@Test @Test
public void withValidation() { public void withValidation() {
load(); load();
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1);
} }
@Test @Test
public void withValidations() { public void withValidations() {
load("hapi.fhir.validation.request-only=false"); load("hapi.fhir.validation.request-only:false");
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2); assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2);
} }
@Test @Test
public void withCustomValidationSchemaLocation() { public void withCustomValidationSchemaLocation() {
load("hapi.fhir.validation.schema-location:custom-schema-location"); load("hapi.fhir.validation.schema-location:custom-schema-location");
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1);
} }
@Test @Test
public void withApacheHttpClient() { public void withApacheHttpClient() {
load(new HidePackagesClassLoader("okhttp3"), "hapi.fhir.server.url:http://localhost:8080"); load(new HidePackagesClassLoader("okhttp3"), "hapi.fhir.server.url:http://localhost:8080");
assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(1); assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(0); assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(0);
} }
@Test @Test
public void withOkHttpClient() { public void withOkHttpClient() {
load("hapi.fhir.server.url:http://localhost:8080"); load("hapi.fhir.server.url:http://localhost:8080");
assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(1); assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(0); assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(0);
} }
private void load(String... environment) { private void load(String... environment) {
load(new Class<?>[] { FhirAutoConfiguration.class }, null, environment); load(new Class<?>[]{FhirAutoConfiguration.class}, null, environment);
} }
private void load(ClassLoader classLoader, String... environment) { private void load(ClassLoader classLoader, String... environment) {
load(new Class<?>[] { FhirAutoConfiguration.class }, classLoader, environment); load(new Class<?>[]{FhirAutoConfiguration.class}, classLoader, environment);
} }
private void load(Class<?>[] configs, String... environment) { private void load(Class<?>[] configs, String... environment) {
load(configs, null, environment); load(configs, null, environment);
} }
private void load(Class<?>[] configs, ClassLoader classLoader, String... environment) { private void load(Class<?>[] configs, ClassLoader classLoader, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
if (classLoader != null) {
applicationContext.setClassLoader(classLoader);
}
if (configs != null) {
applicationContext.register(configs);
}
applicationContext.refresh();
this.context = applicationContext;
}
private static final class HidePackagesClassLoader extends URLClassLoader { MockEnvironment env = new MockEnvironment();
for (String next : environment) {
String nextKey = next.substring(0, next.indexOf(':'));
String nextValue = next.substring(next.indexOf(':') + 1);
env.setProperty(nextKey, nextValue);
}
private final String[] hiddenPackages; AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.setEnvironment(env);
if (classLoader != null) {
applicationContext.setClassLoader(classLoader);
}
if (configs != null) {
applicationContext.register(configs);
}
applicationContext.refresh();
this.context = applicationContext;
}
private HidePackagesClassLoader(String... hiddenPackages) { private static final class HidePackagesClassLoader extends URLClassLoader {
super(new URL[0], FhirAutoConfigurationTest.class.getClassLoader());
this.hiddenPackages = hiddenPackages;
}
@Override private final String[] hiddenPackages;
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
for (String hiddenPackage : this.hiddenPackages) {
if (name.startsWith(hiddenPackage)) {
throw new ClassNotFoundException();
}
}
return super.loadClass(name, resolve);
}
} private HidePackagesClassLoader(String... hiddenPackages) {
super(new URL[0], FhirAutoConfigurationTest.class.getClassLoader());
this.hiddenPackages = hiddenPackages;
}
@Override
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
for (String hiddenPackage : this.hiddenPackages) {
if (name.startsWith(hiddenPackage)) {
throw new ClassNotFoundException();
}
}
return super.loadClass(name, resolve);
}
}
} }

View File

@ -4,14 +4,12 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IGenericClient;
import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)

View File

@ -211,18 +211,18 @@
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<configuration> <configuration>
<classFolders> <!--<classFolders>-->
<classFolder>${basedir}/target/classes</classFolder> <!--<classFolder>${basedir}/target/classes</classFolder>-->
<classFolder>${basedir}/../hapi-fhir-base/target/classes</classFolder> <!--<classFolder>${basedir}/../hapi-fhir-base/target/classes</classFolder>-->
<classFolder>${basedir}/../hapi-fhir-client/target/classes</classFolder> <!--<classFolder>${basedir}/../hapi-fhir-client/target/classes</classFolder>-->
<classFolder>${basedir}/../hapi-fhir-server/target/classes</classFolder> <!--<classFolder>${basedir}/../hapi-fhir-server/target/classes</classFolder>-->
</classFolders> <!--</classFolders>-->
<sourceFolders> <!--<sourceFolders>-->
<sourceFolder>${basedir}/src/main/java</sourceFolder> <!--<sourceFolder>${basedir}/src/main/java</sourceFolder>-->
<sourceFolder>${basedir}/../hapi-fhir-base/src/main/java</sourceFolder> <!--<sourceFolder>${basedir}/../hapi-fhir-base/src/main/java</sourceFolder>-->
<sourceFolder>${basedir}/../hapi-fhir-client/src/main/java</sourceFolder> <!--<sourceFolder>${basedir}/../hapi-fhir-client/src/main/java</sourceFolder>-->
<sourceFolder>${basedir}/../hapi-fhir-server/src/main/java</sourceFolder> <!--<sourceFolder>${basedir}/../hapi-fhir-server/src/main/java</sourceFolder>-->
</sourceFolders> <!--</sourceFolders>-->
<dumpOnExit>true</dumpOnExit> <dumpOnExit>true</dumpOnExit>
</configuration> </configuration>
<executions> <executions>
@ -360,7 +360,8 @@
<package>ca.uhn.fhir.model.dstu2</package> <package>ca.uhn.fhir.model.dstu2</package>
<version>dstu2</version> <version>dstu2</version>
<buildDatatypes>true</buildDatatypes> <buildDatatypes>true</buildDatatypes>
</configuration> <packageName>ca.uhn.fhir.model.dstu2</packageName>
</configuration>
</execution> </execution>
<!-- <execution> <id>clean_source</id> <goals> <goal>minimize-resources</goal> </goals> <configuration> <fhirVersion>DSTU2</fhirVersion> <targetDirectory>${project.baseDir}/../hapi-tinder-plugin/</targetDirectory> <!-- <execution> <id>clean_source</id> <goals> <goal>minimize-resources</goal> </goals> <configuration> <fhirVersion>DSTU2</fhirVersion> <targetDirectory>${project.baseDir}/../hapi-tinder-plugin/</targetDirectory>
</configuration> </execution> --> </configuration> </execution> -->

View File

@ -544,7 +544,8 @@
<slf4j_version>1.7.25</slf4j_version> <slf4j_version>1.7.25</slf4j_version>
<spring_version>5.1.3.RELEASE</spring_version> <spring_version>5.1.3.RELEASE</spring_version>
<spring_data_version>2.1.3.RELEASE</spring_data_version> <spring_data_version>2.1.3.RELEASE</spring_data_version>
<spring-boot.version>1.5.6.RELEASE</spring-boot.version> <!--<spring-boot.version>1.5.6.RELEASE</spring-boot.version>-->
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
<stax2_api_version>3.1.4</stax2_api_version> <stax2_api_version>3.1.4</stax2_api_version>
<thymeleaf-version>3.0.11.RELEASE</thymeleaf-version> <thymeleaf-version>3.0.11.RELEASE</thymeleaf-version>
@ -791,7 +792,7 @@
<dependency> <dependency>
<groupId>javax.validation</groupId> <groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId> <artifactId>validation-api</artifactId>
<version>1.1.0.Final</version> <version>2.0.1.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.ws.rs</groupId> <groupId>javax.ws.rs</groupId>

View File

@ -20,6 +20,7 @@
<li>thymeleaf-spring4 (Testpage Overlay) has been replaced with thymeleaf-spring5</li> <li>thymeleaf-spring4 (Testpage Overlay) has been replaced with thymeleaf-spring5</li>
<li>Commons-Lang3: 3.8 -&gt; 3.8.1</li> <li>Commons-Lang3: 3.8 -&gt; 3.8.1</li>
<li>Commons-Text: 1.4 -&gt; 1.4</li> <li>Commons-Text: 1.4 -&gt; 1.4</li>
<li>Spring Boot: 1.5.6.RELEASE -&gt; 2.1.1.RELEASE</li>
</ul> </ul>
]]> ]]>
</action> </action>