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.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 {
@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.provider.BaseJpaProvider;
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.rest.client.apache.ApacheRestfulClientFactory;
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
@ -46,6 +47,7 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
import okhttp3.OkHttpClient;
import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.*;
@ -69,6 +71,7 @@ import org.springframework.util.CollectionUtils;
import javax.servlet.ServletException;
import javax.sql.DataSource;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
/**
* {@link EnableAutoConfiguration Auto-configuration} for HAPI FHIR.
@ -164,26 +167,11 @@ public class FhirAutoConfiguration {
@ConditionalOnBean(DataSource.class)
@EnableConfigurationProperties(FhirProperties.class)
static class FhirJpaServerConfiguration {
@Bean
@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;
}
@Autowired
private ScheduledExecutorService myScheduledExecutorService;
@Configuration
@EntityScan(basePackages = {"ca.uhn.fhir.jpa.entity", "ca.uhn.fhir.jpa.model.entity"})
@EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data")
static class FhirJpaDaoConfiguration {
@Bean

View File

@ -1,8 +1,5 @@
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.FhirVersionEnum;
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 org.assertj.core.util.Arrays;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
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.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;
@ -36,149 +34,157 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class FhirAutoConfigurationTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext context;
private AnnotationConfigApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void withFhirContext() throws Exception {
load();
assertThat(this.context.getBeansOfType(FhirContext.class)).hasSize(1);
}
@Test
public void withFhirContext() throws Exception {
load();
assertThat(this.context.getBeansOfType(FhirContext.class)).hasSize(1);
}
@Test
public void withFhirVersion() throws Exception {
load(Arrays.array(EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
FhirAutoConfiguration.class),
"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");
assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.DSTU3.getVersionImplementation());
@Test
public void withFhirVersion() throws Exception {
load(Arrays.array(EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
FhirAutoConfiguration.class),
"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");
assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.DSTU3.getVersionImplementation());
load(Arrays.array(EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
FhirAutoConfiguration.class),
"hapi.fhir.version:R4",
"spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles",
"spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory");
assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.R4.getVersionImplementation());
}
load(Arrays.array(EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
FhirAutoConfiguration.class),
"hapi.fhir.version:R4",
"spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles",
"spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory");
assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.R4.getVersionImplementation());
}
@Test
public void withRestfulServer() {
load("hapi.fhir.server.path:/hapi-fhir/*");
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
assertThat(this.context.getBeansOfType(RestfulServer.class)).hasSize(1);
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings()).contains("/hapi-fhir/*");
}
@Test
public void withRestfulServer() {
load("hapi.fhir.server.path:/hapi-fhir/*");
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
assertThat(this.context.getBeansOfType(RestfulServer.class)).hasSize(1);
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings()).contains("/hapi-fhir/*");
}
@Test
public void withJpaServer() {
load(
Arrays.array(
EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
FhirAutoConfiguration.class),
"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");
assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1);
}
@Test
public void withJpaServer() {
load(
Arrays.array(
EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
FhirAutoConfiguration.class),
"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");
assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1);
}
@Test
public void withNoValidation() {
load("hapi.fhir.validation.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(RequestValidatingInterceptor.class);
}
@Test
public void withNoValidation() {
load("hapi.fhir.validation.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(RequestValidatingInterceptor.class);
}
@Test
public void withValidation() {
load();
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1);
}
@Test
public void withValidation() {
load();
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1);
}
@Test
public void withValidations() {
load("hapi.fhir.validation.request-only=false");
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2);
}
@Test
public void withValidations() {
load("hapi.fhir.validation.request-only:false");
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2);
}
@Test
public void withCustomValidationSchemaLocation() {
load("hapi.fhir.validation.schema-location:custom-schema-location");
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1);
}
@Test
public void withCustomValidationSchemaLocation() {
load("hapi.fhir.validation.schema-location:custom-schema-location");
assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1);
}
@Test
public void withApacheHttpClient() {
load(new HidePackagesClassLoader("okhttp3"), "hapi.fhir.server.url:http://localhost:8080");
assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(0);
}
@Test
public void withApacheHttpClient() {
load(new HidePackagesClassLoader("okhttp3"), "hapi.fhir.server.url:http://localhost:8080");
assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(0);
}
@Test
public void withOkHttpClient() {
load("hapi.fhir.server.url:http://localhost:8080");
assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(0);
}
@Test
public void withOkHttpClient() {
load("hapi.fhir.server.url:http://localhost:8080");
assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(0);
}
private void load(String... environment) {
load(new Class<?>[] { FhirAutoConfiguration.class }, null, environment);
}
private void load(String... environment) {
load(new Class<?>[]{FhirAutoConfiguration.class}, null, environment);
}
private void load(ClassLoader classLoader, String... environment) {
load(new Class<?>[] { FhirAutoConfiguration.class }, classLoader, environment);
}
private void load(ClassLoader classLoader, String... environment) {
load(new Class<?>[]{FhirAutoConfiguration.class}, classLoader, environment);
}
private void load(Class<?>[] configs, String... environment) {
load(configs, null, environment);
}
private void load(Class<?>[] configs, String... environment) {
load(configs, null, 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 void load(Class<?>[] configs, ClassLoader classLoader, String... environment) {
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) {
super(new URL[0], FhirAutoConfigurationTest.class.getClassLoader());
this.hiddenPackages = hiddenPackages;
}
private static final class HidePackagesClassLoader extends URLClassLoader {
@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);
}
private final String[] hiddenPackages;
}
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 org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
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.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)

View File

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

View File

@ -544,7 +544,8 @@
<slf4j_version>1.7.25</slf4j_version>
<spring_version>5.1.3.RELEASE</spring_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>
<thymeleaf-version>3.0.11.RELEASE</thymeleaf-version>
@ -791,7 +792,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>

View File

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