The Source for Java Technology Collaboration
User: Password:



Rodrigo Urubatan

Rodrigo Urubatan's Blog

Spring-Annotation v1.0.2 just released

Posted by urubatan on November 29, 2006 at 12:38 PM | Comments (3)

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 to.properties 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="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sa="https://spring-annotation.dev.java.net/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
https://spring-annotation.dev.java.net/context https://spring-annotation.dev.java.net/context.xsd"
default-autowire="byName">
<import resource="classpath*:applicationContext.xml"/>
<sa:annotation-autoload />
</beans>

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

@Bean(name="main")
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");
m.test.printName();
}

}

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:

@Bean
@UrlMapping("/test")
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="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:sa="https://spring-annotation.dev.java.net/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
https://spring-annotation.dev.java.net/context https://spring-annotation.dev.java.net/nonav/context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName">
<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" />
</bean>
</beans>

and then setup your web.xml:

<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring-Annotation Example App</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>net.java.dev.springannotation.utils.FakeWebApplicationContext</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>
</web-app>

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!!


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Can you please explain how your project is different from Spring's own JavaConfig? http://www.springframework.org/javaconfig

    Posted by: euxx on December 01, 2006 at 12:35 PM

  • whell, Spring-Annotation started before they announced their Java Config.
    the Spring-Annotation is Meta-Data based, it looks for the annotated classes and registers it in the Spring context.
    in the Java Config you create manually your objects and returns it as a factory method to the bean factory.

    for the basics it is almost this ...

    but now there is lots more than loading objects with annotations in the Spring-Annotation, the support for JSF is really great, there are annotations for the SpringMVC too ...
    hibernate support
    a litle security module starting to be implemented now (will not be as powerfull as acegi ...

    Posted by: urubatan on December 01, 2006 at 12:53 PM

  • Config you create manually your objects and returns it as a factory method to the bean factory. for the basics it is almost this ... but now there is lots more than loading objects with annotations in the Spring-Annotation, the support for JSF is really great, there are annotations for the SpringMVC too ... hibernate support a litle security module starting to be implemented now (will not be as powerfull as acegi ...


    acrobat
    ad-aware ad-aware
    adulte
    amateur
    amateur2
    amatrice
    anal
    antivirus
    antivirus-gratuit
    anus
    ares
    asian
    asiatique
    ass
    astuce
    auto
    avatar
    avatars
    baise
    bebe
    beurette
    bikini
    bisexuel
    bite
    black
    blague
    blagues
    blonde
    boob
    brune
    carte
    carte2
    carte3
    cartes
    cartes2
    cartes3
    celebrite
    chaleur
    chanson-gratuit


    chansons-gratuit
    charme
    chat-gratuit
    cheat
    cinema
    clip-gratuit
    clitoris
    clone
    cochon
    code-jeu
    coquin
    couille
    couple
    cul
    cul-gratuit
    diaporama
    diaporamas
    divx
    divx-gratuit
    download
    ecran-de-veille
    ecran-de-veille-gratuit
    ecrans-de-veille
    edonkey
    emoticone
    emoticone-gratuit
    emoticones
    emule
    emule-gratuit
    enculer
    enfant
    erotique
    erotiques
    erotisme
    etudiante
    exhibitionniste
    f1-rallye
    familiale
    famille


    fellation
    femme
    femme2
    fesse
    fetiche
    fetichisme
    film
    film2
    film-gratuit
    film-porno-gratuit
    films
    film-x-gratuit
    firefox
    fond-d-ecran
    fond-d-ecran-gratuit
    fonds-d-ecran
    football
    gay
    gay-gratuit
    girl
    golf
    gratuit
    gratuit2
    gratuit3
    gratuite
    gratuite2
    gratuite3
    gros
    grosse
    gros-sein-gratuit
    hard
    hardcore
    hentai-gratuit
    histoire
    homosexuel
    horoscope
    horoscope-gratuit
    horoscopes
    hot

    humour
    icone
    icq
    illusion
    image
    image2
    image-humour
    jeu
    jeu2
    jeu-adulte-gratuit
    jeu-de-voiture-gratuit
    jeu-enfant-gratuit
    jeu-gratuit
    jeu-gratuit-cadeaux
    jeune
    jeu-pc-gratuit
    jeu-video-gratuit
    jeux
    jeux2
    kazaa
    kazaa-gratuit
    latinas
    lesbian
    lesbienne
    limewire
    lingerie
    logiciel
    logiciel2
    logiciel-gratuit
    logiciels
    logiciels2
    logiciels-gratuit
    manga
    massage
    mature
    messenger
    messenger-gratuit
    models
    morpheus


    movie
    mp3-gratuit
    msn
    msn-gratuit
    mure
    music-gratuite
    musique-gratuite
    musiques-gratuites
    nero
    nero-gratuit
    noire
    nu
    nude
    nudiste
    orgasme
    orgie
    parole-gratuit
    paroles-gratuit
    partition
    partitions
    penis
    photo
    photo2
    photo-gay-gratuit
    photo-porno-gratuit
    photo-sexe-gratuit
    photo-sex-gratuit
    pied
    pipe
    poitrine
    porn
    porn-gratuit
    porno
    porno2
    pornographie
    porno-gratuit
    pps-ppt
    programme
    pussy

    rasee
    real-player
    recette
    recettes
    rousse
    sado
    safari
    salope
    sex
    sex2
    sexe
    sexe2
    sexe-amateur-gratuit
    sexe-gratuit
    sex-gratuit
    sex-gratuit-beurette
    sexuelle
    sexy
    shareaza
    skype
    sms-gratuit
    sodomie
    soluce
    solution-jeu
    spectacle
    sport
    sportive
    spybot
    suce
    suceuse
    sudoku-gratuit
    tarot
    tarot-gratuit
    tatouage
    tatouages
    teen
    tele
    telechargement
    telechargement2

    telechargement-antivirus
    telechargement-chanson
    telechargement-chansons
    telechargement-divx
    telechargement-emule
    telechargement-film
    telechargement-film-gratuit
    telechargement-gratuit
    telechargement-kazaa
    telechargement-logiciel
    telechargement-logiciel-gratuit
    telechargement-logiciels
    telechargement-messenger
    telechargement-movie
    telechargement-mp3
    telechargement-msn
    telechargement-music
    telechargement-musique
    telechargement-nero
    telechargement-parole
    telechargement-paroles
    telechargement-porn
    telechargement-porno
    telechargement-sex
    telechargement-sexe
    telechargement-x
    telechargement-xxx
    telecharger
    telecharger2
    telecharger3
    telecharger-antivirus
    telecharger-antivirus2
    telecharger-chanson
    telecharger-chansons
    telecharger-divx
    telecharger-emule
    telecharger-film
    telecharger-gratuit
    telecharger-jeu-gratuit


    telecharger-kazaa
    telecharger-logiciel
    telecharger-logiciels
    telecharger-messenger
    telecharger-movie
    telecharger-mp3
    telecharger-msn
    telecharger-music
    telecharger-musique
    telecharger-nero
    telecharger-parole
    telecharger-paroles
    telecharger-porn
    telecharger-porno
    telecharger-sex
    telecharger-sexe
    telecharger-x
    telecharger-xxx
    television
    tennis
    tit
    toon
    tourisme
    touristique
    tout-gratuit
    traducteur-gratuit
    transsexuelle
    truc
    tuning
    tv
    vacances
    video

    video2
    video-comique
    video-gratuit
    video-porno
    video-porno2
    video-porno-gratuit
    videos
    videos2
    videos-comiques
    video-sexe-gratuit
    video-sex-gratuit
    video-x-gratuit
    vlc
    voiture
    voyage
    voyager
    voyeur
    wallpaper
    webcam
    winamp
    winmx
    winrar
    winzip
    x
    x2
    x-gratuit
    xxx
    xxx-gratuit
    yoga

    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841

    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149

    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37


    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786

    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90

    porno1
    porno2
    porno3
    porno4
    porno5
    porno6
    porno7
    porno8
    porno9
    porno10
    porno11
    porno12
    porno13
    porno14
    porno15
    porno16
    porno17
    porno18
    porno19
    porno20
    porno21
    porno22
    porno23
    porno24
    porno25
    porno26
    porno27
    porno28
    porno29
    porno30

    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62

    1-shareaza
    2-skype
    3-sms-gratuit
    4-sodomie
    5-soluce
    6-spectacle
    7-sport
    8-sportive
    9-sportive
    10-sportive
    11-spybot
    12-suce
    13-suceuse
    14-sudoku-gratuit
    15-tarot-gratuit
    16-tarot
    17-tatouage
    18-tatouages
    19-teen
    20-tele
    21-telechargement-antivirus
    23-telechargement-chansons
    22-telechargement-chanson
    24-telechargement-divx
    25-telechargement-emule
    26-telechargement-film-gratuit
    27-telechargement-film
    28-telechargement-gratuit
    29-telechargement-kazaa
    30-telechargement-logiciel-gratuit
    31-telechargement-logiciel
    32-telechargement-logiciels
    33-telechargement-messenger
    34-telechargement-movie
    36-telechargement-msn
    35-telechargement-mp3
    37-telechargement-music
    38-telechargement-musique
    39-telechargement-nero
    40-telechargement-parole
    41-telechargement-paroles
    42-telechargement-porn
    43-telechargement-porno
    44-telechargement-sex
    45-telechargement-sexe
    46-telechargement-x
    47-telechargement-xxx
    48-telechargement
    49-telechargement
    50-telecharger-antivirus
    51-telecharger-antivirus
    52-telecharger-chanson
    53-telecharger-chansons
    54-telecharger-divx
    55-telecharger-emule
    56-telecharger-film
    57-telecharger-gratuit
    58-telecharger-jeu-gratuit
    59-telecharger-xxx
    60-telecharger-movie
    61-telecharger-sex
    62-telecharger-nero
    63-telecharger-sexe
    64-telecharger-parole
    65-telecharger-paroles
    66-telecharger-porno
    67-telecharger-x
    68-telecharger-messenger
    69-telecharger-music


    1-telecharger
    2-telecharger
    3-telecharger
    4-telecharger-logiciel
    5-telecharger-logiciels
    6-telecharger-mp3
    7-telecharger-msn
    8-telecharger-musique
    9-telecharger-porn
    10-television
    11-tennis
    12-tit
    13-toon
    14-tourisme
    15-touristique
    16-tout-gratuit
    18-transsexuelle
    17-traducteur-gratuit
    19-truc
    20-tuning
    21-tv
    22-vacances
    23-video
    24-video
    25-video-comique
    26-video-gratuit
    27-video-porno
    28-video-porno
    29-video-porno-gratuit
    30-videos
    31-videos-comiques
    32-video-sexe-gratuit
    33-video-sex-gratuit
    34-video-x-gratuit
    35-vlc
    36-voiture
    37-voyage
    38-voyager
    39-voyeur
    40-wallpaper
    41-webcam
    42-winamp
    43-winmx
    44-winrar
    45-winzip
    46-x
    47-x
    48-x-gratuit
    49-xxx
    50-xxx-gratuit
    51-yoga

    Posted by: juanjuanmak on April 01, 2007 at 11:21 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds