JavaWorld
addict
Reged: 06/20/03
Posts: 482
|
|
Implement crosscutting concerns with Spring 2.0
|
Unregistered
|
|
Nice article. Other than the JDBC transaction manager, does spring provide other transaction managers or are there example of custom transaction managrs. AOP sounds perfect for a need we have where we have to provide transactions for a custom data source (not jdbc)
|
Unregistered
|
|
Hi,
It's a bit confusing to see System.out statements in your security aspect as you just laid out the logging aspect to get rid of System.out statements. Not sure whether you can solve it though.
Other than that, nice article.
|
ganesh_ghag
stranger
Reged: 01/10/07
Posts: 2
|
|
Hi, Apart from the JDBC (DataSource) Transaction Manager, spring supports Hibernate and JTA Transaction Manager(for distributed transactions requirement) for non-JDBC custom datasources, you can write custom transaction manager in Spring, by implementing interface PlatformTransactionManager and extending the abstract base class AbstractPlatformTransactionManager
http://www.springframework.org/docs/api/...ionManager.html
cheers, Ganesh
|
ganesh_ghag
stranger
Reged: 01/10/07
Posts: 2
|
|
Hi, Sys.outs in security logging, are only to test functioning of the security aspect as it executes. I agree, even the security aspect, itself can be further enhanced and made to use logging aspect, using (aspect ordering), but depicting that (aspect using another aspect)might have confused the reader, so have not included that in the example source 
cheers, Ganesh
|
Unregistered
|
|
Hi,
It looks I am missing com.myorg.soa.services.entity.spring.test.EntityServiceSpringTest; Could you kindly tell me where can I get the package?
Thanks Feng
|
Drew Gulino
Unregistered
|
|
Nice article. Two fixes needed to get it to work: 1) The article used jdbc:odbc bridge for the security manager. It's easier to use the embedded DB HSQLDB that is included with Spring 2.0. Add lib\hsqldb\hsqldb.jar to the classpath and then modify the my-spring-config.xml: <!-- <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/> <property name="url" value="jdbc:odbc:soadb"/> <property name="username" value="admin"/> <property name="password" value="password"/> </bean> --> <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property> <property name="url"> <value>jdbc:hsqldb:d:/workspace/Spring2aop/db/test</value> </property> <property name="username"><value>sa</value></property> <property name="password"><value></value></property> </bean>
2) Don't know what the EntityServiceSpringTest does but you can get the examples to work by changing MyTest.java: From: AuthenticationManager authenticationManager = (AuthenticationManager)EntityServiceSpringTest.context.getBean("authenticationManager"); To: AuthenticationManager authenticationManager = (AuthenticationManager)context.getBean("authenticationManager");
|
Unregistered
|
|
Hi,
When I try to start the source code that accompanies this article I get an error message:
Code:
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.AspectJExpressionPointcut Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.AspectJExpressionPointcut at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.springframework.aop.config.ConfigBeanDefinitionParser.class$(ConfigBeanDefinitionParser.java:232) at org.springframework.aop.config.ConfigBeanDefinitionParser.createPointcutDefinition(ConfigBeanDefinitionParser.java:544) at org.springframework.aop.config.ConfigBeanDefinitionParser.parsePointcut(ConfigBeanDefinitionParser.java:466) at org.springframework.aop.config.ConfigBeanDefinitionParser.parseAspect(ConfigBeanDefinitionParser.java:258) at org.springframework.aop.config.ConfigBeanDefinitionParser.parse(ConfigBeanDefinitionParser.java:157) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:78) ***
Thanks, M
|
Unregistered
|
|
^ My mistake. I had forgotten to include AspectJ library.
|
Lihua Gao
Unregistered
|
|
You don't need the class. The application context "context" is defined in the class (MyTest) as a static variable.
Lihua Gao gao@sinonet.de
|
Annonymous
Unregistered
|
|
Good article Ganesh. I'm following exactly what you have mentioned for Transaction Management but somehow the transaction management is not working. I've spend lot of time figuring out whats going wrong. Following is my configuration file details: <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="applicationServiceMethods" expression="execution(* com.a.w.applicationservice.BaseService*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="applicationServiceMethods"/> </aop:config>
I've XYZApplicationService which implements BaseService and has two DAO's inside(which I've specified in Bean.xml). To check the transaction management I'm calling one Dao method first (insert) and then another which trows NullPointerException. But first method inserts record in database even though second throws exception. Ideally the first method execution should have been rolled back but it doesn't. The DAO's extend HibernateDaoSupport. Any idea whats going wrong ?
|
Unregistered
|
|
Quote:
Hi,
When I try to start the source code that accompanies this article I get an error message:
Code:
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.AspectJExpressionPointcut Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.AspectJExpressionPointcut at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.springframework.aop.config.ConfigBeanDefinitionParser.class$(ConfigBeanDefinitionParser.java:232) at org.springframework.aop.config.ConfigBeanDefinitionParser.createPointcutDefinition(ConfigBeanDefinitionParser.java:544) at org.springframework.aop.config.ConfigBeanDefinitionParser.parsePointcut(ConfigBeanDefinitionParser.java:466) at org.springframework.aop.config.ConfigBeanDefinitionParser.parseAspect(ConfigBeanDefinitionParser.java:258) at org.springframework.aop.config.ConfigBeanDefinitionParser.parse(ConfigBeanDefinitionParser.java:157) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:78) ***
Thanks, M
|