This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new f4ae17d Spring Boot changes.
f4ae17d is described below
commit f4ae17d488196499037bceaec52af40abd519071
Author: JamesBognar <[email protected]>
AuthorDate: Sat Dec 8 08:56:15 2018 -0500
Spring Boot changes.
---
.../utils/ClasspathResourceFinderSimple.java | 19 ++++-
...ver.html => 02.SpringRestResourceResolver.html} | 2 +-
juneau-doc/src/main/javadoc/overview.html | 89 +++++++++++++++++++---
juneau-doc/src/main/javadoc/resources/docs.txt | 9 ++-
.../main/javadoc/resources/fragments/about.html | 4 +-
.../src/main/javadoc/resources/fragments/toc.html | 7 +-
.../juneau/examples/rest/springboot/App.java | 23 +++---
...Initializer.java => JuneauRestInitializer.java} | 10 +--
...Processor.java => JuneauRestPostProcessor.java} | 64 +++++++++++-----
.../{JuneauIntegration.java => JuneauRest.java} | 25 ++++--
10 files changed, 182 insertions(+), 70 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ClasspathResourceFinderSimple.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ClasspathResourceFinderSimple.java
index 410bfa4..3de00c5 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ClasspathResourceFinderSimple.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ClasspathResourceFinderSimple.java
@@ -65,16 +65,29 @@ public class ClasspathResourceFinderSimple implements
ClasspathResourceFinder {
* @throws IOException
*/
protected InputStream findClasspathResource(Class<?> baseClass, String
name, Locale locale) throws IOException {
- if (locale == null)
- return baseClass.getResourceAsStream(name);
+
+ if (locale == null)
+ return getResourceAsStream(baseClass, name);
+
for (String n : getCandidateFileNames(name, locale)) {
- InputStream is = baseClass.getResourceAsStream(n);
+ InputStream is = getResourceAsStream(baseClass, n);
if (is != null)
return is;
}
return null;
}
+ private InputStream getResourceAsStream(Class<?> baseClass, String
name) {
+ InputStream is = baseClass.getResourceAsStream(name);
+ if (is != null)
+ return is;
+ if (! name.startsWith("/"))
+ is = baseClass.getResourceAsStream("/" + name);
+ if (is != null)
+ return is;
+ return null;
+ }
+
/**
* Returns the candidate file names for the specified file name in the
specified locale.
*
diff --git
a/juneau-doc/docs/Topics/09.juneau-rest-server-springboot/01.SpringRestResourceResolver.html
b/juneau-doc/docs/Topics/09.juneau-rest-server-springboot/02.SpringRestResourceResolver.html
similarity index 99%
rename from
juneau-doc/docs/Topics/09.juneau-rest-server-springboot/01.SpringRestResourceResolver.html
rename to
juneau-doc/docs/Topics/09.juneau-rest-server-springboot/02.SpringRestResourceResolver.html
index 2105729..3ee50a2 100644
---
a/juneau-doc/docs/Topics/09.juneau-rest-server-springboot/01.SpringRestResourceResolver.html
+++
b/juneau-doc/docs/Topics/09.juneau-rest-server-springboot/02.SpringRestResourceResolver.html
@@ -16,7 +16,7 @@
{new} SpringRestResourceResolver
<p>
- The {@link oaj.rest.springboot.SpringRestResourceResolver} class
+ The {@link oaj.rest.springboot.SpringRestResourceResolver} class is an
implementation of
* Implementation of a {@link RestResourceResolver} for resolving resource
classes using Spring.
diff --git a/juneau-doc/src/main/javadoc/overview.html
b/juneau-doc/src/main/javadoc/overview.html
index 66688da..03d9cf0 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -359,9 +359,10 @@
<ol>
<li><p class=''><a class='doclink'
href='#juneau-rest-server-jaxrs.BaseProvider'>Juneau JAX-RS Provider</a></p>
</ol>
- <li><p class='toc2 todo'><a class='doclink'
href='#juneau-rest-server-springboot'>juneau-rest-server-springboot</a></p>
+ <li><p class='toc2 new'><a class='doclink'
href='#juneau-rest-server-springboot'>juneau-rest-server-springboot</a></p>
<ol>
- <li><p class='todo'><a class='doclink'
href='#juneau-rest-server-springboot.TODO'>TODO</a></p>
+ <li><p class='new'><a class='doclink'
href='#juneau-rest-server-springboot.Classes'>Classes</a></p>
+ <li><p class='new'><a class='doclink'
href='#juneau-rest-server-springboot.SpringRestResourceResolver'>SpringRestResourceResolver</a></p>
</ol>
<li><p class='toc2 '><a class='doclink'
href='#juneau-rest-client'>juneau-rest-client</a></p>
<ol>
@@ -454,7 +455,7 @@
<li><p class=''><a class='doclink'
href='#juneau-examples-rest.ConfigResource'>ConfigResource</a></p>
<li><p class=''><a class='doclink'
href='#juneau-examples-rest.LogsResource'>LogsResource</a></p>
</ol>
- <li><p class='toc2 todo'><a class='doclink'
href='#juneau-examples-rest-jetty'>juneau-examples-rest</a></p>
+ <li><p class='toc2 todo'><a class='doclink'
href='#juneau-examples-rest-jetty'>juneau-examples-rest-jetty</a></p>
<ol>
<li><p class='todo'><a class='doclink'
href='#juneau-examples-rest-jetty.Classes'>Classes</a></p>
<li><p class='todo'><a class='doclink'
href='#juneau-examples-rest-jetty.DeployingToHeroku'>Deploying to Heroku</a></p>
@@ -21386,7 +21387,7 @@
<!--
====================================================================================================
-->
-<h2 class='topic todo' onclick='toggle(this)'><a
href='#juneau-rest-server-springboot' id='juneau-rest-server-springboot'>9 -
juneau-rest-server-springboot</a></h2>
+<h2 class='topic new' onclick='toggle(this)'><a
href='#juneau-rest-server-springboot' id='juneau-rest-server-springboot'>9 -
juneau-rest-server-springboot</a></h2>
<div class='topic'><!-- START: 9 - juneau-rest-server-springboot -->
<h5 class='figure'>Maven Dependency</h5>
<p class='bpcode w500'>
@@ -21404,22 +21405,88 @@
<h5 class='figure'>OSGi Module</h5>
<p class='bpcode w500'>
- org.apache.juneau.rest.springboot_{@property juneauVersion}.jar
+ org.apache.juneau.rest.server.springboot_{@property juneauVersion}.jar
</p>
<p>
- The <code>juneau-rest-server-springboot</code> library provides classes
to make it easy to deploy Juneau
- REST resources within the Spring Boot framework.
+ The <code>juneau-rest-server-springboot</code> library provides classes
to make it easy to integrate
+ Juneau REST resources with Spring and Spring Boot.
</p>
<!--
====================================================================================================
-->
-<h3 class='topic todo' onclick='toggle(this)'><a
href='#juneau-rest-server-springboot.TODO'
id='juneau-rest-server-springboot.TODO'>9.1 - TODO</a></h3>
-<div class='topic'><!-- START: 9.1 - juneau-rest-server-springboot.TODO -->
+<h3 class='topic new' onclick='toggle(this)'><a
href='#juneau-rest-server-springboot.Classes'
id='juneau-rest-server-springboot.Classes'>9.1 - Classes</a></h3>
+<div class='topic'><!-- START: 9.1 - juneau-rest-server-springboot.Classes -->
<p>
TODO
</p>
-</div><!-- END: 9.1 - juneau-rest-server-springboot.TODO -->
+</div><!-- END: 9.1 - juneau-rest-server-springboot.Classes -->
+
+<!--
====================================================================================================
-->
+
+<h3 class='topic new' onclick='toggle(this)'><a
href='#juneau-rest-server-springboot.SpringRestResourceResolver'
id='juneau-rest-server-springboot.SpringRestResourceResolver'>9.2 -
SpringRestResourceResolver</a></h3>
+<div class='topic'><!-- START: 9.2 -
juneau-rest-server-springboot.SpringRestResourceResolver -->
+<p>
+ The {@link
org.apache.juneau.rest.springboot.SpringRestResourceResolver} class
+
+
+ * Implementation of a {@link RestResourceResolver} for resolving resource
classes using Spring.
+ *
+ * <p>
+ * Used for resolving resource classes defined via {@link
RestResource#children()}.
+ *
+ * <p>
+ * A typical usage pattern for registering a Juneau REST resource class is
shown below:
+ *
+ * <p class='bpcode w800'>
+ * <ja>@Configuration</ja>
+ * <jk>public class</jk> MySpringConfiguration {
+ *
+ * <ja>@AutoWired</ja>
+ * <jk>private static volatile</jk> ApplicationContext
<jsf>appContext</jsf>;
+ *
+ * <ja>@Bean</ja>
+ * <jk>public</jk> RestResourceResolver
restResourceResolver(ApplicationContext appContext) {
+ * <jk>return new</jk>
SpringRestResourceResolver(appContext);
+ * }
+ *
+ * <ja>@Bean</ja>
+ * <jk>public</jk> RootRest root(RestResourceResolver resolver) {
+ * <jk>return new</jk>
RootRest().setRestResourceResolver(resolver);
+ * }
+ *
+ * <ja>@Bean</ja>
+ * <jk>public</jk> ServletRegistrationBean
rootRegistration(RootRest root) {
+ * <jk>return new</jk> ServletRegistrationBean(root,
<jsf>CONTEXT_ROOT</jsf>, <jsf>CONTEXT_ROOT</jsf>+<js>"/"</js>,
<jsf>CONTEXT_ROOT</jsf>+<js>"/*"</js>);
+ * }
+ * </p>
+
+</p>
+public class SpringRestResourceResolver extends BasicRestResourceResolver {
+
+ private ApplicationContext applicationContext;
+
+ /**
+ * Constructor.
+ *
+ * @param applicationContext The spring application context object.
+ */
+ public SpringRestResourceResolver(ApplicationContext
applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ @Override /* RestResourceResolver */
+ public <T> T resolve(Object parent, Class<T> c, RestContextBuilder
builder, Object...args) {
+ T resource = null;
+ try {
+ resource = applicationContext.getBean(c);
+ } catch (Exception e) { /* Ignore */ }
+ if (resource == null)
+ resource = super.resolve(parent, c, builder);
+ return resource;
+ }
+}
+</div><!-- END: 9.2 - juneau-rest-server-springboot.SpringRestResourceResolver
-->
</div><!-- END: 9 - juneau-rest-server-springboot -->
<!--
====================================================================================================
-->
@@ -27232,7 +27299,7 @@
<!--
====================================================================================================
-->
-<h2 class='topic todo' onclick='toggle(this)'><a
href='#juneau-examples-rest-jetty' id='juneau-examples-rest-jetty'>16 -
juneau-examples-rest</a></h2>
+<h2 class='topic todo' onclick='toggle(this)'><a
href='#juneau-examples-rest-jetty' id='juneau-examples-rest-jetty'>16 -
juneau-examples-rest-jetty</a></h2>
<div class='topic'><!-- START: 16 - juneau-examples-rest-jetty -->
<h5 class='figure'>Archive File</h5>
<p class='bpcode w500'>
diff --git a/juneau-doc/src/main/javadoc/resources/docs.txt
b/juneau-doc/src/main/javadoc/resources/docs.txt
index 774753b..16fe6b2 100644
--- a/juneau-doc/src/main/javadoc/resources/docs.txt
+++ b/juneau-doc/src/main/javadoc/resources/docs.txt
@@ -91,9 +91,9 @@ juneau-dto.Swagger = #juneau-dto.Swagger, Overview >
juneau-dto > Swagger
juneau-dto.SwaggerUI = #juneau-dto.SwaggerUI, Overview > juneau-dto > Swagger
UI
juneau-examples-core = #juneau-examples-core, Overview > juneau-examples-core
juneau-examples-rest = #juneau-examples-rest, Overview > juneau-examples-rest
-juneau-examples-rest-jetty = #juneau-examples-rest-jetty, Overview >
juneau-examples-rest
-juneau-examples-rest-jetty.Classes = #juneau-examples-rest-jetty.Classes,
Overview > juneau-examples-rest > Classes
-juneau-examples-rest-jetty.DeployingToHeroku =
#juneau-examples-rest-jetty.DeployingToHeroku, Overview > juneau-examples-rest
> Deploying to Heroku
+juneau-examples-rest-jetty = #juneau-examples-rest-jetty, Overview >
juneau-examples-rest-jetty
+juneau-examples-rest-jetty.Classes = #juneau-examples-rest-jetty.Classes,
Overview > juneau-examples-rest-jetty > Classes
+juneau-examples-rest-jetty.DeployingToHeroku =
#juneau-examples-rest-jetty.DeployingToHeroku, Overview >
juneau-examples-rest-jetty > Deploying to Heroku
juneau-examples-rest-springboot = #juneau-examples-rest-springboot, Overview >
juneau-examples-rest-springboot
juneau-examples-rest-springboot.Classes =
#juneau-examples-rest-springboot.Classes, Overview >
juneau-examples-rest-springboot > Classes
juneau-examples-rest-springboot.DeployingToHeroku =
#juneau-examples-rest-springboot.DeployingToHeroku, Overview >
juneau-examples-rest-springboot > Deploying to Heroku
@@ -255,7 +255,8 @@ juneau-rest-server = #juneau-rest-server, Overview >
juneau-rest-server
juneau-rest-server-jaxrs = #juneau-rest-server-jaxrs, Overview >
juneau-rest-server-jaxrs
juneau-rest-server-jaxrs.BaseProvider =
#juneau-rest-server-jaxrs.BaseProvider, Overview > juneau-rest-server-jaxrs >
Juneau JAX-RS Provider
juneau-rest-server-springboot = #juneau-rest-server-springboot, Overview >
juneau-rest-server-springboot
-juneau-rest-server-springboot.TODO = #juneau-rest-server-springboot.TODO,
Overview > juneau-rest-server-springboot > TODO
+juneau-rest-server-springboot.Classes =
#juneau-rest-server-springboot.Classes, Overview >
juneau-rest-server-springboot > Classes
+juneau-rest-server-springboot.SpringRestResourceResolver =
#juneau-rest-server-springboot.SpringRestResourceResolver, Overview >
juneau-rest-server-springboot > SpringRestResourceResolver
juneau-rest-server.BuiltInParameters = #juneau-rest-server.BuiltInParameters,
Overview > juneau-rest-server > Built-in Parameters
juneau-rest-server.ClassHierarchy = #juneau-rest-server.ClassHierarchy,
Overview > juneau-rest-server > Class Hierarchy
juneau-rest-server.ClientVersioning = #juneau-rest-server.ClientVersioning,
Overview > juneau-rest-server > Client Versioning
diff --git a/juneau-doc/src/main/javadoc/resources/fragments/about.html
b/juneau-doc/src/main/javadoc/resources/fragments/about.html
index bc8175c..abed929 100644
--- a/juneau-doc/src/main/javadoc/resources/fragments/about.html
+++ b/juneau-doc/src/main/javadoc/resources/fragments/about.html
@@ -21,9 +21,9 @@
<li><b>juneau-svl</b><br>A simple yet powerful variable replacement
language API.
<li><b>juneau-config</b><br>A sophisticated configuration file API.
<li><b>juneau-rest-server</b><br>A universal REST server API for
creating Swagger-based self-documenting REST interfaces using POJOs, simply
deployed as
- one or more top-level servlets in any Servlet 3.1.0+ container.
+ one or more top-level servlets in any Servlet 3.1.0+ container
or Spring Boot.
<li><b>juneau-rest-client</b><br>A universal REST client API for
interacting with Juneau or 3rd-party REST interfaces using POJOs and proxy
interfaces.
- <li><b>juneau-microservice</b><br>A REST microservice API that combines
all the features above with a simple configurable Jetty server for
+ <li><b>juneau-microservice</b><br>A REST microservice API that combines
all the features above as a simple configurable Jetty server for
creating lightweight standalone REST interfaces that start up
in milliseconds.
</ul>
<p>
diff --git a/juneau-doc/src/main/javadoc/resources/fragments/toc.html
b/juneau-doc/src/main/javadoc/resources/fragments/toc.html
index 99f1c20..0543a58 100644
--- a/juneau-doc/src/main/javadoc/resources/fragments/toc.html
+++ b/juneau-doc/src/main/javadoc/resources/fragments/toc.html
@@ -302,9 +302,10 @@
<ol>
<li><p class=''><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-server-jaxrs.BaseProvider'>Juneau JAX-RS
Provider</a></p>
</ol>
- <li><p class='toc2 todo'><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-server-springboot'>juneau-rest-server-springboot</a></p>
+ <li><p class='toc2 new'><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-server-springboot'>juneau-rest-server-springboot</a></p>
<ol>
- <li><p class='todo'><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-server-springboot.TODO'>TODO</a></p>
+ <li><p class='new'><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-server-springboot.Classes'>Classes</a></p>
+ <li><p class='new'><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-server-springboot.SpringRestResourceResolver'>SpringRestResourceResolver</a></p>
</ol>
<li><p class='toc2 '><a class='doclink'
href='{OVERVIEW_URL}#juneau-rest-client'>juneau-rest-client</a></p>
<ol>
@@ -397,7 +398,7 @@
<li><p class=''><a class='doclink'
href='{OVERVIEW_URL}#juneau-examples-rest.ConfigResource'>ConfigResource</a></p>
<li><p class=''><a class='doclink'
href='{OVERVIEW_URL}#juneau-examples-rest.LogsResource'>LogsResource</a></p>
</ol>
- <li><p class='toc2 todo'><a class='doclink'
href='{OVERVIEW_URL}#juneau-examples-rest-jetty'>juneau-examples-rest</a></p>
+ <li><p class='toc2 todo'><a class='doclink'
href='{OVERVIEW_URL}#juneau-examples-rest-jetty'>juneau-examples-rest-jetty</a></p>
<ol>
<li><p class='todo'><a class='doclink'
href='{OVERVIEW_URL}#juneau-examples-rest-jetty.Classes'>Classes</a></p>
<li><p class='todo'><a class='doclink'
href='{OVERVIEW_URL}#juneau-examples-rest-jetty.DeployingToHeroku'>Deploying to
Heroku</a></p>
diff --git
a/juneau-examples/juneau-examples-rest-springboot/src/main/java/org/apache/juneau/examples/rest/springboot/App.java
b/juneau-examples/juneau-examples-rest-springboot/src/main/java/org/apache/juneau/examples/rest/springboot/App.java
index df887a8..f6f8781 100644
---
a/juneau-examples/juneau-examples-rest-springboot/src/main/java/org/apache/juneau/examples/rest/springboot/App.java
+++
b/juneau-examples/juneau-examples-rest-springboot/src/main/java/org/apache/juneau/examples/rest/springboot/App.java
@@ -17,32 +17,27 @@ import org.apache.juneau.rest.springboot.*;
import org.apache.juneau.rest.springboot.annotations.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.*;
-import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RestController;
/**
* Entry point for Examples REST application when deployed as a Spring Boot
application.
*/
@SpringBootApplication
-@JuneauIntegration(rootResources = RootResources.class)
@Controller
-@RestController
public class App {
- private static volatile ConfigurableApplicationContext ctx;
-
public static void main(String[] args) {
- ctx = new SpringApplicationBuilder(App.class)
- .initializers(new JuneauContextInitializer(App.class))
+ new SpringApplicationBuilder(App.class)
+ .initializers(new JuneauRestInitializer(App.class))
.run(args);
}
- public static void start() {
- main(new String[0]);
- }
-
- public static void stop() {
- ctx.stop();
+ /**
+ * Our root resource.
+ */
+ @Bean @JuneauRest
+ public RootResources getRootResources() {
+ return new RootResources();
}
}
diff --git
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauContextInitializer.java
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauRestInitializer.java
similarity index 84%
rename from
juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauContextInitializer.java
rename to
juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauRestInitializer.java
index 985b273..e7ac5c3 100644
---
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauContextInitializer.java
+++
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauRestInitializer.java
@@ -12,7 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.springboot;
-import org.apache.juneau.rest.springboot.annotations.JuneauIntegration;
+import org.apache.juneau.rest.springboot.annotations.JuneauRest;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
@@ -20,10 +20,10 @@ import
org.springframework.context.ConfigurableApplicationContext;
* Spring Boot context initializer for Juneau REST resources.
*
* <p>
- * Looks for the {@link JuneauIntegration} annotation on the Spring
application class to automatically
+ * Looks for the {@link JuneauRest} annotation on the Spring application class
to automatically
* register Juneau REST resources.
*/
-public class JuneauContextInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext> {
+public class JuneauRestInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext> {
private final Class<?> appClass;
@@ -32,14 +32,14 @@ public class JuneauContextInitializer implements
ApplicationContextInitializer<C
*
* @param appClass The Spring application class.
*/
- public JuneauContextInitializer(Class<?> appClass) {
+ public JuneauRestInitializer(Class<?> appClass) {
this.appClass = appClass;
}
@Override /* ApplicationContextInitializer */
public void initialize(ConfigurableApplicationContext ctx) {
ctx.addBeanFactoryPostProcessor(
- new JuneauIntegrationPostProcessor(ctx, appClass)
+ new JuneauRestPostProcessor(ctx, appClass)
);
}
}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauIntegrationPostProcessor.java
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauRestPostProcessor.java
similarity index 59%
rename from
juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauIntegrationPostProcessor.java
rename to
juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauRestPostProcessor.java
index 0caa24c..8a19fca 100644
---
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauIntegrationPostProcessor.java
+++
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/JuneauRestPostProcessor.java
@@ -13,24 +13,28 @@
package org.apache.juneau.rest.springboot;
import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.springboot.annotations.JuneauIntegration;
+import org.apache.juneau.rest.springboot.annotations.JuneauRest;
import org.springframework.beans.BeansException;
-import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.*;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.*;
+import org.springframework.core.type.*;
+
+import java.util.*;
import javax.servlet.Servlet;
/**
- * Processes the {@link JuneauIntegration} annotation on the Spring
application class.
+ * Processes the {@link JuneauRest} annotation on the Spring application class
and <ja>@Bean</ja> methods.
*/
-public class JuneauIntegrationPostProcessor implements
BeanDefinitionRegistryPostProcessor {
+public class JuneauRestPostProcessor implements
BeanDefinitionRegistryPostProcessor {
- private final ConfigurableApplicationContext ctx;
private final Class<?> appClass;
+ private final RestResourceResolver restResourceResolver;
+ private BeanDefinitionRegistry registry;
/**
* Constructor.
@@ -38,34 +42,52 @@ public class JuneauIntegrationPostProcessor implements
BeanDefinitionRegistryPos
* @param ctx The spring application context.
* @param appClass The spring application class.
*/
- public JuneauIntegrationPostProcessor(ConfigurableApplicationContext ctx,
Class<?> appClass) {
+ public JuneauRestPostProcessor(ConfigurableApplicationContext ctx,
Class<?> appClass) {
this.appClass = appClass;
- this.ctx = ctx;
+ this.restResourceResolver = new SpringRestResourceResolver(ctx);
}
@Override /* BeanDefinitionRegistryPostProcessor */
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry
registry) {
+ this.registry = registry;
+ }
- JuneauIntegration a = appClass.getAnnotation(JuneauIntegration.class);
+ @Override /* BeanDefinitionRegistryPostProcessor */
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
+ try {
+ Map<String,RestServlet> m = new LinkedHashMap<>();
- if (a == null || a.rootResources().length == 0)
- return;
+ // @JuneauRest on App class.
+ if (appClass != null) {
+ JuneauRest a = appClass.getAnnotation(JuneauRest.class);
+ if (a != null)
+ for (Class<? extends RestServlet> c :
a.servlets())
+ m.put(c.getName(), c.newInstance());
+ }
- RestResourceResolver rrr = new SpringRestResourceResolver(ctx);
+ // @JuneauRest on classes.
+ for (Map.Entry<String,Object> e :
beanFactory.getBeansWithAnnotation(JuneauRest.class).entrySet())
+ if (e.getValue() instanceof RestServlet)
+ m.put(e.getKey(),
(RestServlet)e.getValue());
- for (Class<? extends RestServlet> c : a.rootResources()) {
- try {
- RestServlet rs =
c.newInstance().setRestResourceResolver(rrr);
+ // @JuneauRest on @Bean method.
+ for (String beanName :
beanFactory.getBeanNamesForType(RestServlet.class)) {
+ BeanDefinition bd =
beanFactory.getBeanDefinition(beanName);
+ if (bd.getSource() instanceof AnnotatedTypeMetadata) {
+ AnnotatedTypeMetadata metadata =
(AnnotatedTypeMetadata)bd.getSource();
+ if
(metadata.isAnnotated(JuneauRest.class.getName()))
+ m.put(beanName,
(RestServlet)beanFactory.getBean(beanName));
+ }
+ }
+
+ for (RestServlet rs : m.values()) {
+
rs.setRestResourceResolver(restResourceResolver);
ServletRegistrationBean<Servlet> reg = new
ServletRegistrationBean<>(rs, '/' + rs.getPath());
registry.registerBeanDefinition(reg.getServletName(),
new RootBeanDefinition(ServletRegistrationBean.class, () -> reg));
- } catch (Exception e) {
- throw new RuntimeException(e);
}
- }
- }
- @Override /* BeanDefinitionRegistryPostProcessor */
- public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
- // No-op
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
}
diff --git
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/annotations/JuneauIntegration.java
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/annotations/JuneauRest.java
similarity index 75%
rename from
juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/annotations/JuneauIntegration.java
rename to
juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/annotations/JuneauRest.java
index b6deacd..64718a6 100644
---
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/annotations/JuneauIntegration.java
+++
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/annotations/JuneauRest.java
@@ -12,23 +12,36 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.springboot.annotations;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
import org.apache.juneau.rest.RestServlet;
-import org.springframework.stereotype.Component;
+import org.springframework.context.annotation.*;
import java.lang.annotation.*;
/**
* Added to Spring application classes to denote Juneau REST resource classes
to deploy as servlets.
+ *
+ * <p>
+ * The annotation can be used in two places:
+ * <ul class='spaced-list'>
+ * <li>
+ * On the source class of a Spring Boot application.
+ * <li>
+ * On {@link Bean}-annotated methods on configuration beans.
+ * </ul>
*/
-@Target({ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
+@Target({TYPE,METHOD})
+@Retention(RUNTIME)
@Documented
@Inherited
-@Component
-public @interface JuneauIntegration {
+public @interface JuneauRest {
/**
* Specifies one or more implementations of {@link RestServlet} to
deploy as servlets.
+ * <p>
+ * This method is only applicable when used on the source class of a
Spring Boot application.
*/
- Class<? extends RestServlet>[] rootResources();
+ Class<? extends RestServlet>[] servlets() default {};
}