Thoughts on integration Spring with Dropwizard:
The basic approach is to create the Spring context in the Dropwizard service run method, then add the appropriate beans from the context to the Dropwizard environment. See the example by Jacek Furmankiewicz in his git project: dropwizard-spring-di-security-onejar-example.
Component Scan
Adding the @ComponentScan annotation to the configuration bean registered with the context (as in the above example) will enable component scanning in the same package or lower as the configuration bean.
Alternatively, if Camel routes will be used in the application, use an XML configuration file to initialize the Camel context and component scanning:
<context:component-scan base-package="com.example.beans"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<contexScan/>
</camelContext>
This will allow routes declared in Java or Groovy files annotated with @Component to be added to the Camel context (be sure to extend SpringRouteBuilder), in addition to annotated classed being added to the Spring context.
Encrypting Properties
If there is a need to encrypt values in a property file, add the Jasypt EncryptablePropertyPlaceholderConfigurer to the Spring XML configuration file. Its properties can be injected in @Component-annotated classes with the @Value annotation using SpEL on the property or a setter:
@Value(value="${database.username}")
private String username;
Properties that do not require encryption should be injected from the Dropwizard service configuration, which must be registered with the Spring context to make it accessible to the other beans. Alternatively, encrypted properties could be provided by the Dropwizard configuration using the above @Value annotation and decrypted in the setter by an injected Jasypt StandardPBEEncryptor.
ClassPathBeanDefinitionScanner may also be useful in this situation.
No comments:
Post a Comment