Skip to main content

Spring-Annotation v1.0.2 just released

Posted by urubatan on November 29, 2006 at 12:38 PM PST

Some additions to this new version:
* Support for XML Schema Configuration, now you just need to put the tag <sa:annotation-autoload> to enable the annotation module
* There is no need to create the empty anymore if all your classes are in some open directory, you just need it in the root of the jars you want to use the annotations
* new @Alias annotation that enables the configuration of aliases to beans
* Suport for filters in the loading of classes to enable the use in diferent contxts or modules, to enable this just use the tags includePackage or excludePackage inside the <sa:annotation-autoload> , both uses regular expressions to filter the package name.
* The JSF module does not forces the use of the AspectJ loadtimeweaving anymore, working on a way to support both approaches
* Now the annotation reading module supports the use of any kind of annotation, but there is no documentation of it for now, expect some news for the next release
* Added support for some of the JSR 250 annotations, now you can use @PostCreate and @PreDestroy to specify init and destroy methods of your bean, and with the security module (very early stage) you can use the annotations @DenyAll, @PermitAll and @RolesAllowed to configure the secrity of your project
* Started the port of some of the new JSF features, like the new Scopes (flash and conversation) to the basic web module
* now there is no need to add a RequestContextListener to your web.xml it is already included in the dummy.tld inside the web module
* Some more unit tests written for the framework, there is a lot missing yet.
* The litle existent documentation is a litle bether, and the JavaDocs are starting to be written

in resume you can do this:
create a file named appContext.xml and put this inside it:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
<import resource="classpath*:applicationContext.xml"/>
<sa:annotation-autoload />

then you create a java class named Main with this code:

public class Main {
private TestObject test;

* this method should be called from spring to set the variable to the other bean in the context which has the name set to test
* @param test
public void setTestBean(TestObject test) {
this.test = test;

public static void main(String[] args){
ClassPathXmlApplicationContext appctx = new ClassPathXmlApplicationContext("/appContext.xml");
Main m = (Main) appctx.getBean("main");


and another java class named TestObject with this content:

@Bean(name = "testBean")
public class TestObject {
public void printName() {
System.out.println("No Name, just an example");

All set, you have your first application running.
if you want a web application, just do like this:
one java class named ExampleController:

public class ExampleController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
return new ModelAndView("example","message","This page is the /WEB-INF/jsp/example.jsp and it was openned from the Example Controller using the Spring View Resolver");

one applicationContext.xml inside your WEB-INF directory:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi="" xmlns:tx=""
xmlns:aop="" xmlns:sa=""
<import resource="classpath*:applicationContext.xml" />
<sa:annotation-autoload />
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />

and then setup your web.xml:

<web-app version="2.4"
<display-name>Spring-Annotation Example App</display-name>

as you can see, the web.xml is just a vanilla Spring MVC web.xml (the FakeWebApplicationContext is just to make the dispatcher servlet not need the dispatcher-servlet.xml, if you create this file you can remove that parameter)

there are some examples in the project website, and the portuguese version of this post in this blog.
if you liked the idea and want more examples, just comment here and I`ll try to write some more.
or if you would like to contribute with some examples I`ll thank you a lot!!