Tag Archive for 'spring'

Generating Spring IDE Descriptor Files from Maven

My Google Alerts just sent me this and I though it might be worth sharing:

The Eclipse plugin will create/change the .springBeans and the .settings/org.springframework.ide.eclipse.core.prefs. Then you can refresh the Eclipse project (F5) from now the project contains a Spring-Builder which will handle the …#

The same approach should work for the .springWebflow descriptor file.

Furthermore there is IDE-603 to create a Maven plugin that can create those files.

Spring Development the Mylyn Way

screencast-thumb.pngI personally really enjoy organizing my day-to-day development work with Eclipse Mylyn as I find it incredible useful: the way it helps me to keep track of what I’m working on is a immense time saver. Switching between tasks is just a matter of a single click. And there is lots more!

If you haven’t played with Mylyn yourself you can learn more about it by watching the Eclipse Live Mylyn 2.2 webinar.

Since Spring IDE’s Mylyn integration is already around for a couple of months and we haven’t gotten a single comment or JIRA issue with on that, I thought it might be good to promote it a with broader audience. The aim of this integration is to give developers all the advantages of Mylyn’s Task-focused Interface while working with Spring XML configuration files.

spring-ide_mylyn.png

Currently the integration features a Mylyn Structure Bridge at allows Mylyn to add Spring configuration elements - e.g. beans, properties or constructor-args - to the task context. We have added a Focus Filter to the Spring Explorer as well as to the Beans Cross References View that lets you filter those elements that are not relevant to the task. Furthermore the content assist proposals in the XML editor are reordered based on the proposal’s level of interest that is recorded in the task context (see screenshot above). Last but not least we made interest-based code folding for Spring configuration files work in WTP’s XML editor.
I’ve created a screencast that shows the Spring IDE and Mylyn Integration in more detail. The screencast outlines some of the AOP support features too and shows the upcoming support Spring’s <import /> element.

Check out the screencast here and leave a comment if you saw something interesting.

Refinements for NamespaceHandler Utility Classes

With the release of version 2.0.5 of the Spring Framework the API of some namespace-related utility classes has been improved. Here are the related entries from the changelog.txt:

Changes in version 2.0.5 (2007-05-07)
------------------------------------- 

Package org.springframework.beans
* added overloaded "rootBeanDefinition" factory methods with bean class name
  (instead of Class) to BeanDefinitionBuilder
* added “getBeanClassName” template method to AbstractSingleBeanDefinitionParser,
  as alternative to “getBeanClass

#

These two changes allow implementing custom Spring 2.0 configuration namespaces without relying on class loading within the BeanDefinitionParser implementations. That is required if you want your namespace to work with Spring IDE.

More information on implementing tooling-friendly namespaces is available in an older post.

Most Useless Custom Namespace Ever

I was in London the other day to meet with Dave from Interface21 and two colleagues of mine (cheers to Scott and Lucas). One topic of the meeting was related to domain modeling. During the discussion we tried hard to come up with a decent name for a component in our domain model, but couldn’t figure out a descriptive name that would serve our needs well enough.

We were playing around with different names and - you know how that happens during meetings that take the whole day and you start loosing track for a couple of seconds - we started to look for names in other languages than English.

That moment I thought about a custom namespace that is properly the most useless one can think of: A translation of the Spring beans XSD into other languages. This idea sounds like non-sense in the first place, but on my way back at the Heathrow airport I couldn’t resist to think about it in more detail. Finally I ended up scratching a rapid prototype that allows to write bean definitions in my mother language:

<?xml version="1.0" encoding="UTF-8"?>
<bohnen xmlns="http://www.sfw.org/schema/beans-german"
    xsi:schemaLocation="http://www.sfw.org/schema/beans-german
    http://www.sfw.org/schema/beans/spring-beans-german-2.0.xsd"
>

    <bohne id="pet1" klasse="org.springframework.beans.Pet">
        <eigenschaft name="name" wert="kitty1" />
    </bohne>

    <bohne id="pet2" klasse="org.springframework.beans.Pet">
       <konstruktor-arg wert="kitty2" />
       <eigenschaft name="spouse" ref="pet1" />
    </bohne>

</bohnen>

Still, I don’t really see how a translation of the Spring beans XML configuration dialect into other languages can be useful for anyone, but there is already a request for translating Spring’s Exception message to other languages somewhere on the forums.

So what is the story of the post then?

There is one aspect of the preceding example, which I overlooked at the beginning, that could actually become quite useful. As you can see in the example there is not a single XML element from the original Spring dialect used to wire up two Beans. Certainly the syntax looks quite the same as plain Spring, but that is only an example. Even the root beans element is not used.

I wasn’t aware of the fact that with using Spring 2.0 namespaces you can introduce your own DSL to configure components without being tied to Spring’s XML syntax in any way. I haven’t seen a namespace example before that doesn’t use the beans element at least at the root level.

Consequently Spring allows mixing configuration files with different syntax in one ApplicationContext. So you can use a configuration file for your domain services or repositories that uses a Domain Specific Namespace and others for your technical infrastructure services, like transaction or security, that leverage the power of Spring’s XML syntax.

That could be very handy if you are working on a project that applies pattern following DDD. Furthermore that shows how flexible the Spring container is in terms of XML configuration since the introduction of custom namespaces with version 2.0.

The prototype source code of the German namespace handler is available here.

Adding Support for Custom Namespaces

Since version 2.0 Spring supports an XSD-based configuration approach that allows integrating your own DSL for configuration into Spring. How to implement such namespace extension has been documented and the approach has been adopted by several Spring sub-projects and others, e.g. Spring Web Flow and DWR.

In response to an issue in our ticketing system and some comments I got recently, I’m going to introduce Spring IDE’s extension points for plugging in support for your own configuration namespace. These extension points allow you – as a custom namespace developer – to add support for navigation, content assist and validation to Spring IDE.

Continue reading ‘Adding Support for Custom Namespaces’