• How to shoot yourself in the foot with Scala traits and Spring

    Suppose you have some class MyService configured as Spring bean: @Component class MyService extends MyBaseService { def myOperation() { ... } } Which is referenced somewhere in the project: ... @Autowired private var myService: MyService = _ ... So far this code works, and now you'd like to mix in some trait into your service to add common functionality: @Component class MyService extends MyBaseService with MyTrait {
  • Why @RequestMapping may be ignored

    Recently I had a problem with Spring MVC. My mappings made by @RequestMapping annotations were ignored, but I was sure that annotation processor was picking the bean correctly. It turned out that if you use org.springframework.web.servlet.handler.SimpleUrlHandlerMapping to do some mapping in XML then you need to include DefaultAnnotationHandlerMapping explicitly into your application context: <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> This is not needed when you have only annotation-based mapping - then  DefaultAnnotationHandlerMapping is included by default.
  • Beware of SchedulerFactoryBean

    Recently I've discovered unpleasant side effect of org.springframework.scheduling.quartz.SchedulerFactoryBean which results to instable behaviour. It implements FactoryBean interface, so by default if you reference it in your context it returns Scheduler instance instead of the factory itself. But Scheduler instance creation is triggered by SchedulerFactoryBean.afterPropertiesSet(), and factory can't return Scheduler at all until it has been fully initialized. See the point? Suppose we have some cyclic reference in the context and SchedulerFactoryBean relies on some other beans (for example, they may be needed for initial state configuration), and some of those other beans relies on scheduler in order to do some job later.
  • Spring WebFlow input patameters default values

    Due to strange WebFlow behaviour (possibly a bug) it was impossible for me to use a constant as a default input value - I was constantly getting OgnlException. So, I used following workaround. Suppose you have such input parameter in your flow definition and you want 'true' to be default value: <input name="myFlag" type="boolean"/> Then define some action state as initial state (<flow start-state="myFirstState">) and set default value there: