|
Annotations vs. xml configuration The purpose of this article is to sum up pros and cons of java annotation and xml configurations. Spring is the most popular application development framework for enterprise Java™. Millions of developers use Spring to create high performing, easily testable, reusable code without any lock-in. So does Lexaden! Java-based container configuration
The central artifact in Spring's new Java-configuration support is the @Configuration-annotated class. These classes consist principally of @Bean-annotated methods that define instantiation, configuration, and initialization logic for objects to be managed by the Spring IoC container. Annotating a class with the @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. You can find a full Spring 3 reference documentation here There are some pros and cons of annotation configuration:
We combined both approaches - java annotations and essential xml minimum that gave us benefits of both without shortcomings.
@Configuration public class AccountServiceContext { @Bean public UserAccountService accountService() { return new UserAccountServiceImpl(); } @Bean @Scope(BeanDefinition.SCOPE_PROTOTYPE) public RegisterAccountForm registerAccountForm() { return new RegisterAccountForm(); } @Bean @State(REGISTER_ACCOUNT) @Placeholder(CONTENT) @Scope(BeanDefinition.SCOPE_PROTOTYPE) public RegisterAccountController registerAccountController() { return new RegisterAccountController(); } }
<flow xmlns="..."> <module id="authentication" initial="login" extends="module"> <controller id="login" extends="controller"> <on event="account.details" to="account.details"/> <on event="register.account" to="register.account"/> </controller> <controller id="account.details" extends="controller"> <on event="cancel" to="login"/> </controller> <controller id="register.account" extends="controller" > <view id="displayView" extends="controller/displayView"> <on event="register" to="register"/> </view> <action id="register" extends="action"> <on event="error" to="displayView"/> </action> <final id="register" extends="action"/> </controller> <on event="login" to="login"/> <on event="cancel" to="platform"/> </module> </flow>
|


