Enabling Non-Spring Libraries to Access Spring Boot Components: Difference between revisions
Jump to navigation
Jump to search
Line 13: | Line 13: | ||
=Approach= | =Approach= | ||
The Spring Boot runtime should implement a Spring component whose job is to configure a dedicated class in the dependency package. This solution assumes that the dependency package "cooperates" and we can write code in it. The dedicated class in the dependency package is conventionally named SpringApplicationContextAccess. | The Spring Boot runtime should implement a Spring component whose job is to configure a dedicated class in the dependency package. This solution assumes that the dependency package "cooperates" and we can write code in it. The dedicated class in the dependency package is conventionally named SpringApplicationContextAccess: | ||
<syntaxhighlight lang='java'> | |||
package playground.springboot.dependency; | |||
import org.springframework.context.ApplicationContext; | |||
public class SpringApplicationContextAccess { | |||
public static ApplicationContext APPLICATION_CONTEXT; | |||
} | |||
</syntaxhighlight> | |||
Note that the dependency project should be configured with "compile only" access to Spring Framework API packages "" and "". A way to do this that does not involve Spring Boot dependency management is described here: [[Gradle_Spring_dependency-management_Plugin#Overview|Spring dependency-management Plugin for Gradle]]. |
Revision as of 17:43, 2 November 2018
Internal
Overview
This article describes a possible approach to give non-Spring libraries access to Spring Boot runtime components.
Playground Example
Approach
The Spring Boot runtime should implement a Spring component whose job is to configure a dedicated class in the dependency package. This solution assumes that the dependency package "cooperates" and we can write code in it. The dedicated class in the dependency package is conventionally named SpringApplicationContextAccess:
package playground.springboot.dependency;
import org.springframework.context.ApplicationContext;
public class SpringApplicationContextAccess {
public static ApplicationContext APPLICATION_CONTEXT;
}
Note that the dependency project should be configured with "compile only" access to Spring Framework API packages "" and "". A way to do this that does not involve Spring Boot dependency management is described here: Spring dependency-management Plugin for Gradle.