Posts tagged with #spring


Defining error format is important part of REST API design.

Spring-Boot and Spring Security provide pretty nice error handling for RESTful APIs out of the box. Although it has to be documented, especially when contract-first approach to API design is used.

It is good idea to follow some common format for error responses. But OAuth2 specification and Spring Boot format may not satisfy those requirements.

Spring Framework offers very flexible means for binding application components. Externalizable properties, composite configuration, nested application contexts and profiles.

Sometimes, it is necessary to control whether particular beans or @Configuration will be loaded or not. Spring Framework v.4.1.x does not provide that feature out of the box. But, hopefully, Spring allows conditional bean initialization (see @Profile implementation and @Configurable). So, I created the annotation @Enabled which allows me to control bean instantiation via properties.

@Enabled indicates that a component is eligible for registration when evaluated expression is true. This annotation should be used in conjunction with Configuration and Bean annotations.

Deploying to Apache Tomcat often requires making changes to default configuration. These changes are often environment specific. Also, when upgrading a Tomcat to new version you need to be sure that all your custom changes have not been lost and were applied to new configuration. To deal with all that stuff Tomcat via separation of the configuration. This post contains step-by-step instruction will help you to establish custom tomcat configuration.

Read SpringFratamework’s reference here: http://static.springframework.org/spring/docs/2.5.x/reference/ejb.html#ejb-implementation-ejb3 Place to ejb module’s classpath a file beanRefContext.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="myBeanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg value="myApplicationContext.xml"/> </bean> </beans> Create application context file named myApplicationContext.xml and define you beans there. Place this file to the ejb module’s classpath. Annotate your Stateless Session Bean: @Stateless @Interceptors(org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.class) public class MyFacadeBean implements MyFacade { @Autowired private MySpringComponent component; ... public void foo() { component.