All Projects → grayshirts → spring-ctx-groovy

grayshirts / spring-ctx-groovy

Licence: Apache-2.0 license
Contain the class `ctx.App` that exposes the Spring context statically

Programming Languages

groovy
2714 projects

Projects that are alternatives of or similar to spring-ctx-groovy

Spring-Boot-Application-Template
Spring Boot Web App, Flyway, MySQL, H2DB, Bootstrap, Thymeleaf, JWT, Swagger, API Rate Limiting, Docker, RBAC, i18n
Stars: ✭ 90 (+542.86%)
Mutual labels:  spring-boot-actuator
multi-ctx
Multiple Spring Contexts Showcase
Stars: ✭ 16 (+14.29%)
Mutual labels:  spring-context
infinispan-spring-boot
Infinispan Spring Boot starter. Use this starter in your Spring Boot applications to help you use Infinispan+Spring integration in embedded and client/server mode
Stars: ✭ 61 (+335.71%)
Mutual labels:  spring-boot-actuator
kafka-health-check
Health Check for Apache Kafka
Stars: ✭ 30 (+114.29%)
Mutual labels:  spring-boot-actuator
sample-spring-kotlin-microservice
sample spring boot application written in kotlin using spring boot actuator for managing app and swagger2 for API documentation
Stars: ✭ 35 (+150%)
Mutual labels:  spring-boot-actuator
spring-boot-starter-shell
Spring Shell with Spring Boot Driven
Stars: ✭ 17 (+21.43%)
Mutual labels:  spring-shell
course-spring-microservices
Code examples built for the purpose of video course: Microservices With Spring Boot And Spring Cloud
Stars: ✭ 74 (+428.57%)
Mutual labels:  spring-boot-actuator

Spring Context from Groovy

Spring Context from Groovy

spring-ctx-groovy contain the class ctx.App, that it's built with Groovy and exposes the Spring context statically.

You can get a bean object from the context like this in Java, without the need to inject the bean into your class:

MyUserService myUserService = (MyUserService) ctx.App.getContext().getBean("myUserService");

Or like this with Groovy:

def myUserService = ctx.App.myUserService

But the most important feature is to use it with the Remote Shell included in the Spring Boot Actuator module, to access within the console through a SSH session to the Spring Context using the repl groovy, like in the awesome Grails Console.

⚠️ [Deprecated Module] Unfortunately, because the project rely on the Remote Shell that was discontinued in Spring Boot 2.0+, the project only works with Spring Boot 1.x projects. To debug a Spring Boot 2.0+ project with a shell console, try jshell-plugin along with spring-ctx. Though they have some limitations, like the need to build the project with JDK 9 or higher, and using Gradle (Maven not supported).

$ ssh -p 2000 user@localhost
user@localhost's password:
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v1.4.6.RELEASE) on myhost
> repl groovy
Using repl groovy
> ctx.App.myUserService.findUserByEmail("[email protected]")[0].id
100123
> ctx.App.myUserService.getById(100123).name
Mariano Ruiz
> ctx.App.contactDao.logger.effectiveLevel
INFO
> ctx.App.contactDao.logger.setLevel(ch.qos.logback.classic.Level.DEBUG)

Also exposes the properties of the project with the prop static method:

> ctx.App.prop("server.context-path")
/api

When an object is returned, the repl prints a representation of the object (call the toString() method), but sometimes is not the best way to read the result, or you just need a JSON representation:

> ctx.App.json(statusObj)
{"queue_info":{"active_count":0,"core_pool_size":50}}

The default ObjectMapper is used to serialize to JSON.

NOTE: You DON'T need to develop your project with Groovy to use this library in your Spring Project and access to the ctx.App class from your source code, or from the remote shell.

Configuration

To add this library to your project, depending of your building tool, these are the configuration settings you need:

Maven

Add the following configuration to the pom.xml file of your project:

  1. dependencies section:

    <dependency>
        <groupId>ar.com.grayshirts</groupId>
        <artifactId>spring-ctx-groovy</artifactId>
        <version>1.1.0</version>
    </dependency>
    <!-- Remote Shell Library for Spring Boot applications -->
    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-remote-shell</artifactId>
    </dependency>
  2. repositories section:

    <repository>
        <id>grayshirts-public</id>
        <name>Grayshirts Public Repository</name>
        <url>https://dl.bintray.com/grayshirts/public</url>
    </repository>

Gradle

Add the following configuration to the build.gradle file of your project:

  1. dependencies section:

    compile 'ar.com.grayshirts:spring-ctx-groovy:1.1.0'
    // Remote Shell Library for Spring Boot applications
    compile 'org.springframework.boot:spring-boot-starter-remote-shell'
  2. repositories section:

    maven() {
        url "https://dl.bintray.com/grayshirts/public"
    }

System Requirements

  • JDK 7+

Build & Publish

Compile and build the .jar locally with:

$ ./gradlew build

Publish to your local Maven repo:

$ ./gradlew publishToMavenLocal

Upload to Bintray repo:

$ ./gradlew bintrayUpload

Links

About

Project: https://github.com/grayshirts/spring-ctx-groovy

Bintray Artifacts Repository: https://bintray.com/grayshirts/public/spring-ctx-groovy

Author: Mariano Ruiz [email protected]

License: Apache Software License 2.0.

(2017) Grayshirts.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].