With Spring Boot Actuator we get some useful endpoints in our application to check on our application when it is running.
One of the endpoints is the /info
endpoint.
We can add information about our application if Spring Boot finds a file META-INF/build-info.properties
in the classpath of our application.
With the Gradle Spring Boot plugin we can generate the build-info.properties
file.
When we apply the Gradle Spring Boot plugin to our project we get a Gradle extension springBoot
in our build file.
With this extension we can configure Spring Boot for our project.
To generate project information that is used by the /info
endpoint we must add the method statement buildInfo()
inside the springBoot
extension.
With this method statement the Gradle Spring Boot plugin generates a file build/main/resources/META-INF/build-info.properties.
.
Let’s run our application and send a request for /info
:
Continue reading →
Securing an application is difficult.
Securing an entire application landscape is even more difficult! In this modern era of blazing fast microservices we do not want the additional complexity of having to secure it all manually.
This is where Spring Cloud Security comes in.
By combining proven technologies, it helps us achieve performant, configurable end-to-end security across multiple applications.
So what technologies are being combined? Well, a lot...
We will not mention them all here, but the foundation relies on Spring Boot and Spring Security OAuth.
OAuth, or, in our case, OAuth2 is basically an authorization delegation protocol.
To quote Wikipedia, OAuth:
[...] specifies a process for resource owners to authorize third-party access to their server resources without sharing their credentials.
Continue reading →
When we a have Spring managed application, we want to let Spring manage all of our beans. Beside the regular way of creating beans with known solutions like Annotated beans, Java Configuration and XML Configuration, there is also a way in which we can create our own BeanDefinition
. With a BeanDefinitionRegistryPostProcessor
it is possible to create a specific post processor which can add BeanDefinition
s to the BeanDefinitionRegistry
. It differs from the BeanPostProcessor
, which only has hooks for Bean Initialization (construction of your POJO), where the BeanDefinitionRegistryPostProcessor
has a hook on the BeanDefinitionRegistry
. This gives us the ability to define our own BeanDefinition
. First we create a BeanDefinitionRegistryPostProcessor
implementation as listed in the example. We implement the required method, and will be able to add our own bean definition to the registry. The defined BeanDefinition
will be picked up by the ApplicationContext
and the POJO will be constructed. Our result is A Spring managed bean
package com.jdriven;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;
@Component
public class LogicServiceRegistryPostProcessor
implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
RootBeanDefinition beanDefinition =
new RootBeanDefinition(MyServiceImpl.class); //The service implementation
serviceDefinition.setTargetType(MyService.class); //The service interface
serviceDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
registry.registerBeanDefinition("myBeanName", beanDefinition );
}
}
Continue reading →