You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by bb...@apache.org on 2017/09/08 19:38:15 UTC

nifi-registry git commit: NIFIREG-16 Initial Spring Boot integration for nifi-registry-web-api - Refactoring the wiring of the application to leverage Spring

Repository: nifi-registry
Updated Branches:
  refs/heads/master 7fa56bea9 -> d93eab365


NIFIREG-16 Initial Spring Boot integration for nifi-registry-web-api
- Refactoring the wiring of the application to leverage Spring

This closes #9.


Project: http://git-wip-us.apache.org/repos/asf/nifi-registry/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-registry/commit/d93eab36
Tree: http://git-wip-us.apache.org/repos/asf/nifi-registry/tree/d93eab36
Diff: http://git-wip-us.apache.org/repos/asf/nifi-registry/diff/d93eab36

Branch: refs/heads/master
Commit: d93eab3656e88230b560b1085d0773ff803a63a2
Parents: 7fa56be
Author: Bryan Bende <bb...@apache.org>
Authored: Wed Sep 6 14:12:22 2017 -0400
Committer: Bryan Bende <bb...@apache.org>
Committed: Fri Sep 8 15:37:51 2017 -0400

----------------------------------------------------------------------
 nifi-registry-framework/pom.xml                 | 12 +++++
 .../provider/StandardProviderFactory.java       | 10 +++-
 .../serialization/FlowSnapshotSerializer.java   |  2 +
 .../nifi/registry/service/RegistryService.java  | 16 +++++--
 .../nifi/registry/service/TestService.java      | 31 +++++++++++++
 nifi-registry-jetty/pom.xml                     |  8 ++--
 .../apache/nifi/registry/jetty/JettyServer.java | 15 ++----
 nifi-registry-web-api/pom.xml                   | 33 +++++++++++++
 .../web/NiFiRegistryApiApplication.java         | 44 ++++++++++++++++++
 .../web/NiFiRegistryPropertiesFactory.java      | 46 ++++++++++++++++++
 .../web/NiFiRegistryResourceConfig.java         | 49 ++++++--------------
 .../registry/web/api/BucketFlowResource.java    |  5 +-
 .../nifi/registry/web/api/BucketResource.java   |  5 +-
 .../nifi/registry/web/api/FlowResource.java     |  5 +-
 .../nifi/registry/web/api/TestResource.java     | 27 ++++++-----
 .../src/main/webapp/WEB-INF/web.xml             | 45 ------------------
 pom.xml                                         | 26 +++++++++++
 17 files changed, 262 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-framework/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/pom.xml b/nifi-registry-framework/pom.xml
index 00bd2d6..7ad7468 100644
--- a/nifi-registry-framework/pom.xml
+++ b/nifi-registry-framework/pom.xml
@@ -76,6 +76,18 @@
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-validator</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-framework/src/main/java/org/apache/nifi/registry/provider/StandardProviderFactory.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/provider/StandardProviderFactory.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/provider/StandardProviderFactory.java
index 03b5a86..918ab79 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/provider/StandardProviderFactory.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/provider/StandardProviderFactory.java
@@ -23,8 +23,12 @@ import org.apache.nifi.registry.provider.generated.Property;
 import org.apache.nifi.registry.provider.generated.Providers;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
 import org.xml.sax.SAXException;
 
+import javax.annotation.PostConstruct;
 import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -43,6 +47,7 @@ import java.util.concurrent.atomic.AtomicReference;
 /**
  * Standard implementation of ProviderFactory.
  */
+@Configuration
 public class StandardProviderFactory implements ProviderFactory {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(StandardProviderFactory.class);
@@ -68,7 +73,7 @@ public class StandardProviderFactory implements ProviderFactory {
     private FlowPersistenceProvider flowPersistenceProvider;
     private MetadataProvider metadataProvider;
 
-    public StandardProviderFactory(final NiFiRegistryProperties properties) {
+    public StandardProviderFactory(@Autowired final NiFiRegistryProperties properties) {
         this.properties = properties;
 
         if (this.properties == null) {
@@ -76,6 +81,7 @@ public class StandardProviderFactory implements ProviderFactory {
         }
     }
 
+    @PostConstruct
     @Override
     public synchronized void initialize() throws ProviderFactoryException {
         if (providersHolder.get() == null) {
@@ -102,6 +108,7 @@ public class StandardProviderFactory implements ProviderFactory {
         }
     }
 
+    @Bean
     @Override
     public synchronized MetadataProvider getMetadataProvider() {
         if (metadataProvider == null) {
@@ -134,6 +141,7 @@ public class StandardProviderFactory implements ProviderFactory {
         return metadataProvider;
     }
 
+    @Bean
     @Override
     public synchronized FlowPersistenceProvider getFlowPersistenceProvider() {
         if (flowPersistenceProvider == null) {

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/FlowSnapshotSerializer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/FlowSnapshotSerializer.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/FlowSnapshotSerializer.java
index ae2482b..de88e8c 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/FlowSnapshotSerializer.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/FlowSnapshotSerializer.java
@@ -18,6 +18,7 @@ package org.apache.nifi.registry.serialization;
 
 import org.apache.nifi.registry.flow.VersionedFlowSnapshot;
 import org.apache.nifi.registry.serialization.jaxb.JAXBFlowSnapshotSerializer;
+import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -35,6 +36,7 @@ import java.util.Map;
  * read from the InputStream to determine the version, and then the InputStream will be passed to the deserializer
  * for the given version.
  */
+@Service
 public class FlowSnapshotSerializer implements Serializer<VersionedFlowSnapshot> {
 
     static final String MAGIC_HEADER = "Flows";

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
index 6f53957..6ca999c 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
@@ -32,6 +32,8 @@ import org.apache.nifi.registry.metadata.MetadataProvider;
 import org.apache.nifi.registry.metadata.StandardBucketMetadata;
 import org.apache.nifi.registry.metadata.StandardFlowMetadata;
 import org.apache.nifi.registry.serialization.Serializer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.ConstraintViolationException;
@@ -39,12 +41,14 @@ import javax.validation.Validator;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.stream.Collectors;
 
+@Service
 public class RegistryService {
 
     private final MetadataProvider metadataProvider;
@@ -56,14 +60,18 @@ public class RegistryService {
     private final Lock readLock = lock.readLock();
     private final Lock writeLock = lock.writeLock();
 
-    public RegistryService(final MetadataProvider metadataProvider,
-                           final FlowPersistenceProvider flowPersistenceProvider,
-                           final Serializer<VersionedFlowSnapshot> snapshotSerializer,
-                           final Validator validator) {
+    public RegistryService(@Autowired final MetadataProvider metadataProvider,
+                           @Autowired final FlowPersistenceProvider flowPersistenceProvider,
+                           @Autowired final Serializer<VersionedFlowSnapshot> snapshotSerializer,
+                           @Autowired final Validator validator) {
         this.metadataProvider = metadataProvider;
         this.flowPersistenceProvider = flowPersistenceProvider;
         this.snapshotSerializer = snapshotSerializer;
         this.validator = validator;
+        Objects.requireNonNull(this.metadataProvider);
+        Objects.requireNonNull(this.flowPersistenceProvider);
+        Objects.requireNonNull(this.snapshotSerializer);
+        Objects.requireNonNull(this.validator);
     }
 
     private <T>  void validate(T t, String invalidMessage) {

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/TestService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/TestService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/TestService.java
new file mode 100644
index 0000000..3160fc1
--- /dev/null
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/TestService.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.registry.service;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * Test service to verify spring-boot will correctly inject into JAX-RS resource TestResource.
+ */
+@Service
+public class TestService {
+
+    public String test() {
+        return "Testing";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-jetty/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-registry-jetty/pom.xml b/nifi-registry-jetty/pom.xml
index 38e6442..e47a354 100644
--- a/nifi-registry-jetty/pom.xml
+++ b/nifi-registry-jetty/pom.xml
@@ -51,14 +51,14 @@
             <artifactId>jetty-servlets</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-lang3</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-annotations</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>apache-jsp</artifactId>
             <scope>compile</scope>

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java b/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
index 9f71e5f..0712e38 100644
--- a/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
+++ b/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
@@ -16,8 +16,6 @@
  */
 package org.apache.nifi.registry.jetty;
 
-import org.apache.nifi.registry.security.AuthorizationProvider;
-import org.apache.nifi.registry.security.AuthorizedUserFilter;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.registry.properties.NiFiRegistryProperties;
 import org.eclipse.jetty.annotations.AnnotationConfiguration;
@@ -30,7 +28,6 @@ import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.SslConnectionFactory;
 import org.eclipse.jetty.server.handler.HandlerCollection;
-import org.eclipse.jetty.servlet.FilterHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.webapp.Configuration;
@@ -40,8 +37,6 @@ import org.eclipse.jetty.webapp.WebAppContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
@@ -51,7 +46,6 @@ import java.net.SocketException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.EnumSet;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.List;
@@ -215,9 +209,13 @@ public class JettyServer {
         }
 
         webUiContext = loadWar(webUiWar, "/nifi-registry");
+
         webApiContext = loadWar(webApiWar, "/nifi-registry-api");
         webApiContext.setAttribute("nifi-registry.properties", properties);
 
+        // there is an issue scanning the asm repackaged jar so narrow down what we are scanning
+        webApiContext.setAttribute("org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern", ".*/spring-[^/]*\\.jar$");
+
         final HandlerCollection handlers = new HandlerCollection();
         handlers.addHandler(webUiContext);
         handlers.addHandler(webApiContext);
@@ -284,11 +282,6 @@ public class JettyServer {
                 }
             }
 
-            // add the authorization filter
-            final Filter authorizationFilter = new AuthorizedUserFilter(new AuthorizationProvider(properties));
-            webUiContext.addFilter(new FilterHolder(authorizationFilter), "/*", EnumSet.allOf(DispatcherType.class));
-            webApiContext.addFilter(new FilterHolder(authorizationFilter), "/*", EnumSet.allOf(DispatcherType.class));
-
             dumpUrls();
         } catch (final Throwable t) {
             throw new RuntimeException("Unable to start up: " + t, t);

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/pom.xml b/nifi-registry-web-api/pom.xml
index 94478eb..7253e0c 100644
--- a/nifi-registry-web-api/pom.xml
+++ b/nifi-registry-web-api/pom.xml
@@ -34,6 +34,17 @@
         </resources>
         <plugins>
             <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring.boot.version}</version>
+            </plugin>
+            <plugin>
+                <artifactId>maven-war-plugin</artifactId>
+                <configuration>
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
+                </configuration>
+            </plugin>
+            <plugin>
                 <groupId>com.github.kongchen</groupId>
                 <artifactId>swagger-maven-plugin</artifactId>
                 <version>3.1.5</version>
@@ -88,6 +99,28 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>${spring.boot.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-jersey</artifactId>
+            <version>${spring.boot.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+            <version>${spring.boot.version}</version>
+        </dependency>
+        <!-- Must be marked provided in order to produce a correct WAR -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-tomcat</artifactId>
+            <version>${spring.boot.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.nifi.registry</groupId>
             <artifactId>nifi-registry-properties</artifactId>
             <version>0.0.1-SNAPSHOT</version>

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryApiApplication.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryApiApplication.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryApiApplication.java
new file mode 100644
index 0000000..9d2f5a4
--- /dev/null
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryApiApplication.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.registry.web;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.ComponentScan;
+
+/**
+ * Main class for starting the NiFi Registry Web API as a Spring Boot application.
+ *
+ * By default, Spring Boot will only scan in the package this class is located in, so we set
+ * @ComponentScan to the common parent package to find beans in other packages.
+ */
+@SpringBootApplication
+@ComponentScan("org.apache.nifi.registry")
+public class NiFiRegistryApiApplication extends SpringBootServletInitializer {
+
+    @Override
+    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+        return application.sources(NiFiRegistryApiApplication.class);
+    }
+
+    public static void main(String[] args) {
+        SpringApplication.run(NiFiRegistryApiApplication.class, args);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryPropertiesFactory.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryPropertiesFactory.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryPropertiesFactory.java
new file mode 100644
index 0000000..85e9784
--- /dev/null
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryPropertiesFactory.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.registry.web;
+
+import org.apache.nifi.registry.properties.NiFiRegistryProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.context.ServletContextAware;
+
+import javax.servlet.ServletContext;
+
+/**
+ * The JettyServer puts an instance of NiFiRegistryProperties into the ServletContext, so this class
+ * obtains that instance and makes it available to inject into all other places.
+ *
+ */
+@Configuration
+public class NiFiRegistryPropertiesFactory implements ServletContextAware {
+
+    private NiFiRegistryProperties properties;
+
+    @Override
+    public void setServletContext(ServletContext servletContext) {
+        properties = (NiFiRegistryProperties) servletContext.getAttribute("nifi-registry.properties");
+    }
+
+    @Bean
+    public NiFiRegistryProperties getNiFiRegistryProperties() {
+        return properties;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryResourceConfig.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryResourceConfig.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryResourceConfig.java
index 02ece9d..7a6ac13 100644
--- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryResourceConfig.java
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/NiFiRegistryResourceConfig.java
@@ -16,15 +16,6 @@
  */
 package org.apache.nifi.registry.web;
 
-import org.apache.nifi.registry.flow.FlowPersistenceProvider;
-import org.apache.nifi.registry.flow.VersionedFlowSnapshot;
-import org.apache.nifi.registry.metadata.MetadataProvider;
-import org.apache.nifi.registry.properties.NiFiRegistryProperties;
-import org.apache.nifi.registry.provider.ProviderFactory;
-import org.apache.nifi.registry.provider.StandardProviderFactory;
-import org.apache.nifi.registry.serialization.FlowSnapshotSerializer;
-import org.apache.nifi.registry.serialization.Serializer;
-import org.apache.nifi.registry.service.RegistryService;
 import org.apache.nifi.registry.web.api.BucketFlowResource;
 import org.apache.nifi.registry.web.api.BucketResource;
 import org.apache.nifi.registry.web.api.FlowResource;
@@ -38,37 +29,23 @@ import org.glassfish.jersey.server.ServerProperties;
 import org.glassfish.jersey.server.filter.HttpMethodOverrideFilter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Configuration;
 
 import javax.servlet.ServletContext;
-import javax.validation.Validation;
-import javax.validation.Validator;
-import javax.validation.ValidatorFactory;
 import javax.ws.rs.core.Context;
 
+/**
+ * This is the main Jersey configuration for the application.
+ *
+ *  NOTE: Don't set @ApplicationPath here because it has already been set to 'nifi-registry-api' in JettyServer
+ */
+@Configuration
 public class NiFiRegistryResourceConfig extends ResourceConfig {
 
     private static final Logger logger = LoggerFactory.getLogger(NiFiRegistryResourceConfig.class);
 
     public NiFiRegistryResourceConfig(@Context ServletContext servletContext) {
-        final NiFiRegistryProperties properties = (NiFiRegistryProperties) servletContext.getAttribute("nifi-registry.properties");
-
-        // create the providers
-        final ProviderFactory providerFactory = new StandardProviderFactory(properties);
-        providerFactory.initialize();
-
-        final MetadataProvider metadataProvider = providerFactory.getMetadataProvider();
-        final FlowPersistenceProvider flowPersistenceProvider = providerFactory.getFlowPersistenceProvider();
-
-        // create a serializer for flow snapshots
-        final Serializer<VersionedFlowSnapshot> snapshotSerializer = new FlowSnapshotSerializer();
-
-        // create a validator
-        final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
-        final Validator validator = validatorFactory.getValidator();
-
-        // create the main services that the REST resources will use
-        final RegistryService registryService = new RegistryService(metadataProvider, flowPersistenceProvider, snapshotSerializer, validator);
-
+        // register filters
         register(HttpMethodOverrideFilter.class);
 
         // register the exception mappers
@@ -78,10 +55,12 @@ public class NiFiRegistryResourceConfig extends ResourceConfig {
         register(new ThrowableMapper());
 
         // register endpoints
-        register(new TestResource(metadataProvider, flowPersistenceProvider));
-        register(new BucketResource(registryService));
-        register(new BucketFlowResource(registryService));
-        register(new FlowResource(registryService));
+        register(BucketResource.class);
+        register(BucketFlowResource.class);
+        register(FlowResource.class);
+
+        // test endpoint to exercise spring dependency injection
+        register(TestResource.class);
 
         property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
     }

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
index 218205b..7933e87 100644
--- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
@@ -22,6 +22,8 @@ import org.apache.nifi.registry.flow.VersionedFlow;
 import org.apache.nifi.registry.service.RegistryService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.POST;
@@ -31,6 +33,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+@Component
 @Path("/buckets/{bucketId}/flows")
 @Api(
         value = "bucket >> flows",
@@ -42,7 +45,7 @@ public class BucketFlowResource {
 
     private final RegistryService registryService;
 
-    public BucketFlowResource(final RegistryService registryService) {
+    public BucketFlowResource(@Autowired final RegistryService registryService) {
         this.registryService = registryService;
     }
 

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketResource.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketResource.java
index 797ea9e..b5f2d93 100644
--- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketResource.java
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketResource.java
@@ -25,6 +25,8 @@ import org.apache.nifi.registry.bucket.Bucket;
 import org.apache.nifi.registry.service.RegistryService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -40,6 +42,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import java.util.Set;
 
+@Component
 @Path("/buckets")
 @Api(
         value = "/buckets",
@@ -55,7 +58,7 @@ public class BucketResource {
 
     private final RegistryService registryService;
 
-    public BucketResource(final RegistryService registryService) {
+    public BucketResource(@Autowired final RegistryService registryService) {
         this.registryService = registryService;
     }
 

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/FlowResource.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/FlowResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/FlowResource.java
index f210a3d..6298aa5 100644
--- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/FlowResource.java
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/FlowResource.java
@@ -27,6 +27,8 @@ import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata;
 import org.apache.nifi.registry.service.RegistryService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -41,6 +43,7 @@ import javax.ws.rs.core.Response;
 import java.util.Set;
 import java.util.SortedSet;
 
+@Component
 @Path("/flows")
 @Api(
         value = "/flows",
@@ -52,7 +55,7 @@ public class FlowResource {
 
     private final RegistryService registryService;
 
-    public FlowResource(final RegistryService registryService) {
+    public FlowResource(@Autowired final RegistryService registryService) {
         this.registryService = registryService;
     }
 

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/TestResource.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/TestResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/TestResource.java
index cc6d846..1f6e1ba 100644
--- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/TestResource.java
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/TestResource.java
@@ -16,9 +16,11 @@
  */
 package org.apache.nifi.registry.web.api;
 
-import org.apache.nifi.registry.flow.FlowPersistenceProvider;
-import org.apache.nifi.registry.metadata.MetadataProvider;
+import org.apache.nifi.registry.properties.NiFiRegistryProperties;
+import org.apache.nifi.registry.service.TestService;
 import org.apache.nifi.registry.web.response.TestEntity;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -26,30 +28,27 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+@Component
 @Path("/test")
 public class TestResource {
 
-    private final MetadataProvider metadataProvider;
+    private TestService testService;
 
-    private final FlowPersistenceProvider flowPersistenceProvider;
+    private NiFiRegistryProperties properties;
 
-    public TestResource(final MetadataProvider metadataProvider, final FlowPersistenceProvider flowPersistenceProvider) {
-        this.metadataProvider = metadataProvider;
-        this.flowPersistenceProvider = flowPersistenceProvider;
+    public TestResource(@Autowired TestService testService, @Autowired NiFiRegistryProperties properties) {
+        this.testService = testService;
+        this.properties = properties;
 
-        if (this.metadataProvider == null) {
-            throw new IllegalStateException("MetadataProvider cannot be null");
-        }
-
-        if (this.flowPersistenceProvider == null) {
-            throw new IllegalStateException("FlowPersistenceProvider cannot be null");
+        if (this.properties == null) {
+            throw new IllegalStateException("Properties cannot be null");
         }
     }
 
     @GET
     @Produces(MediaType.APPLICATION_JSON)
     public Response getTest() {
-        final TestEntity testEntity = new TestEntity("testing");
+        final TestEntity testEntity = new TestEntity(testService.test());
         return Response.ok(testEntity).build();
     }
 

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/nifi-registry-web-api/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/webapp/WEB-INF/web.xml b/nifi-registry-web-api/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index ea67a48..0000000
--- a/nifi-registry-web-api/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-      http://www.apache.org/licenses/LICENSE-2.0
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
-    <display-name>nifi-registry-api</display-name>
-    
-    <servlet>
-        <servlet-name>api</servlet-name>
-        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
-        <init-param>
-            <param-name>javax.ws.rs.Application</param-name>
-            <param-value>org.apache.nifi.registry.web.NiFiRegistryResourceConfig</param-value>
-        </init-param>
-    </servlet>
-    <servlet-mapping>
-        <servlet-name>api</servlet-name>
-        <url-pattern>/*</url-pattern>
-    </servlet-mapping>
-    
-    <filter>
-        <filter-name>gzipCompressionFilter</filter-name>
-        <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
-        <init-param>
-            <param-name>methods</param-name>
-            <param-value>get,post,put</param-value>
-        </init-param>
-    </filter>
-    <filter-mapping>
-        <filter-name>gzipCompressionFilter</filter-name>
-        <url-pattern>/*</url-pattern>
-    </filter-mapping>
-    
-</web-app>

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/d93eab36/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 91dbfaa..1fbdb53 100644
--- a/pom.xml
+++ b/pom.xml
@@ -104,6 +104,9 @@
         <org.slf4j.version>1.7.12</org.slf4j.version>
         <jetty.version>9.4.3.v20170317</jetty.version>
         <jersey.version>2.25.1</jersey.version>
+        <!-- spring.version should always match the version of spring used by the version of spring-boot -->
+        <spring.boot.version>1.5.6.RELEASE</spring.boot.version>
+        <spring.version>4.3.10.RELEASE</spring.version>
     </properties>
 
     <repositories>
@@ -208,6 +211,11 @@
             </dependency>
             <dependency>
                 <groupId>org.eclipse.jetty</groupId>
+                <artifactId>jetty-annotations</artifactId>
+                <version>${jetty.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.eclipse.jetty</groupId>
                 <artifactId>apache-jsp</artifactId>
                 <version>${jetty.version}</version>
             </dependency>
@@ -272,6 +280,24 @@
                 <artifactId>javax.el</artifactId>
                 <version>3.0.1-b08</version>
             </dependency>
+            <!-- These Spring dependencies should end up in the REST API through spring-boot, but we need the framework
+                    module to declare Spring beans, so ensure the Spring version lines up with the version of spring-boot -->
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-beans</artifactId>
+                <version>${spring.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-core</artifactId>
+                <version>${spring.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-context</artifactId>
+                <version>${spring.version}</version>
+            </dependency>
+            <!-- End Spring dependencies -->
             <dependency>
                 <groupId>org.apache.commons</groupId>
                 <artifactId>commons-lang3</artifactId>