使用注入的spring服务service.listAll()我有以下例外:
Caused by: org.springframework.aop.framework.adapter.UnknownAdviceTypeException:
Advice object [null] is neither a supported subinterface of
[org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor]
at org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry.getInterceptors(DefaultAdvisorAdapterRegistry.java:88)
at org.springframework.aop.framework.DefaultAdvisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(DefaultAdvisorChainFactory.java:61)
at org.springframework.aop.framework.AdvisedSupport.getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport.java:482)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:188)
配置类
@Configuration
@EnableTransactionManagement
@PropertySource("classpath:system/db.properties")
@ComponentScan("com.agitech.agitech.service")
public class ContextConfig {
protected static Log log = LogFactory.getLog(ContextConfig.class);
@Resource
private Environment env;
public void setEnv(Environment env) {
this.env = env;
}
private final Properties hibProperties() {
Properties properties = new Properties();
properties.put( HIBERNATE_DIALECT, env.getRequiredProperty(HIBERNATE_DIALECT) );
properties.put( HIBERNATE_SHOW_SQL, env.getRequiredProperty(HIBERNATE_SHOW_SQL) );
properties.put( "hibernate.bytecode.provider", "javassist" );
properties.put( "hibernate.listeners.envers.autoRegister", false );
return properties;
}
@Bean(name ="dataSource")
public DataSource dataSource() {
return dataSource( env.getRequiredProperty(DATABASE_URL) );
}
@Bean(name ="mgrJPA")
public JpaTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
public DataSource dataSource(String url) {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getRequiredProperty(DATABASE_DRIVER));
dataSource.setUrl(url);
dataSource.setUsername(env.getRequiredProperty(DATABASE_USERNAME));
dataSource.setPassword(env.getRequiredProperty(DATABASE_PASSWORD));
return dataSource;
}
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
DataSource dataSource, String unitName, String... packages) {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean =
new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource( dataSource );
entityManagerFactoryBean.setPersistenceProviderClass( HibernatePersistence.class );
entityManagerFactoryBean.setPackagesToScan( packages );
entityManagerFactoryBean.setJpaProperties( hibProperties() );
entityManagerFactoryBean.setPersistenceUnitName( unitName );
return entityManagerFactoryBean;
}
@Bean(name ="mgrEMF")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
return entityManagerFactory(dataSource(), "mgrUnit", Contract.class.getPackage().getName());
}
}
答案 0 :(得分:0)
问题在于我没有使用@Transactional注释来对服务的listAll过程进行注释,但我认为,鉴于它只是选择查询我不需要事务
答案 1 :(得分:0)
很可能你在Spring配置文件中缺少<context:annotation-config/>
,因此拦截器不会被注入PointcutAdvisor