Reputation: 195
I'm using Eclipse Juno IDE.
I have a java application.
In the program I have those classes: Team.java Player.java Now I'm enabling the user to add a new player to the team, the user gives me the player data. and for each player there is a log file.
Now when the player is added to the team an event is occur "Player was added to the team" what i want to do is to log this event and write what occur in the player's log file.
I want to handle those logging issues with Spring AOP. so how it can be done?
All the examples I saw are using with applicationContext.xml file. what I need to write in this file, if the players are create dynamically?
Upvotes: 3
Views: 438
Reputation: 340883
While some tutorials make you believe Spring is used to define dependencies between value objects, like House
bean has dependency on Door
and Heating
beans, etc. - typical Spring application is not built like that. Beans are normally used to declare stateless, singleton services, once and for good. There isn't much dynamic stuff going around after bootstrap.
However you can use Spring in your example. Just define player as prototype, lazy initialized bean:
<bean class="Player" scope="prototype" lazy-init="true"/>
And every time you need a new Player
, ask container for it:
applicationContext.getBean(Player.class);
Returned bean will be fully functioning Spring bean, except that Spring won't call @PreDestroy
callback. But AOP will work.
Upvotes: 2