это мой первый проект с использованием весеннего АОП.Существует проблема, когда я добавляю
<aop:aspectj-autoproxy proxy-target-class="true" />
в мой spring-servlet.xml.Если я прокомментирую эту строку из контекстных файлов, приложение будет работать нормально и без ошибок.
Если я добавлю эту строку, будет выдано исключение.
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myItemController' defined in file [C:\Users\mmunaf\spring_boot_MSes_In30Minutes\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\ItemServices\WEB-INF\classes\com\mywmos\itemservices\controller\MyItemController.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot resolve reference to bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' while setting bean property 'transactionAttributeSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: List [Xlint:invalidAbsoluteTypeName]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1230)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1174)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5409)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5707)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1702)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1692)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Это мой класс аспектов.
@Aspect
@Component
public class MyItemDaoLoggingAspect {
//this is wher we add all aspect logic
//@Before advice
@Before("execution(public List getAllItems())")
public void beforeVaalidateMyItem() {
System.out.println(" ========> In MyItemDaoLoggingAspect");
System.out.println(" ========> Executing beforeAscpect for validateMyItem");
}
}
Это мой метод дао.
public List getAllItems() {
Session session = sessionFactory.getCurrentSession();
return session.createCriteria(MyItem.class).list();
}
Это файл конфигурации моего приложения.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan
base-package="com.mywmos" />
<mvc:annotation-driven />
<tx:annotation-driven />
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="${oracle.driver-calss}" />
<property name="username" value="${oracle.userName}" />
<property name="password" value="${oracle.password}" />
<property name="url" value="${oracle.Url}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan"
value="com.mywmos.itemservices.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${oracle.hbm2ddl}</prop>
<prop key="hibernate.dialect">${oracle.dialect}</prop>
<prop key="hibernate.show_sql">${oracle.show_sql}</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="propertyPlaceHolderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>db.properties</value>
</property>
</bean>
<bean id="appCtxBProvider"
class="com.mywmos.itemservices.util.ApplicationContextProvider" />
<bean id="myCollDemoBean"
class="com.mywmos.itemservices.model.CollectionsDemo">
<property name="mySet">
<set>
<value>1</value>
<value>2</value>
<value>${oracle.show_sql}</value>
</set>
</property>
</bean>
</beans>
Пожалуйста, дайте мне знать, если вам нужны какие-либо другие детали.Спасибо.