BeanCreationException: ошибка при создании bean-компонента с именем «org.springframework.context.annotation.internalPersistenceAnnotationProcessor»: не удалось создать экземпляр bean-компонента; вложенным исключением является java.lang.ClassFormatError: атрибут отсутствия кода в методе, который не является собственным или абстрактным в файле класса javax/persistence/PersistenceContextType
получается следующая ошибка:
... 12 more
2015-07-06 23:03:06 [main] DEBUG DefaultListableBeanFactory:512 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@105fece7: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,baseSpringConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,org.openrepose.dbutil.spring.config.DbUtilsSpringConfig,sessionFactory,dataSource,hibernateUtil,hibernateUtils,org.openrepose.dao.model.spring.config.DaoSpringConfig,clientAuthConfigDao,ipIdentityConfigDao,rackspaceAuthorizationDao,quotaDao,rateLimitingConfigurationDao,systemModelDao,rackspaceAuthorizationConverter,ipIdentityConfigConverter,quotaConverter,rateLimitingConfigurationBase,clientAuthConfigConverter,rateLimitingConfigurationConverter,systemModelConverter,systemModelBase,quotaBase,ipIdentityConfigBase,clientAuthConfigBase,rackspaceAuthorizationBase]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalPersistenceAnnotationProcessor': Instantiation of bean failed; nested exception is java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/PersistenceContextType
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1093)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1038)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:199)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.(AnnotationConfigApplicationContext.java:84)
at org.openrepose.base.test.TestManagerBase.main(TestManagerBase.java:71)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/PersistenceContextType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at org.springframework.util.ClassUtils.getMethodIfAvailable(ClassUtils.java:668)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.(PersistenceAnnotationBeanPostProcessor.java:173)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1086)
... 12 more
Сценарий:
У меня есть несколько проектов модулей.
модель: объект hibernate
dbutils: внедрение фабрики сеансов hibernate имеет модель в качестве зависимости
dao: операция, связанная с dao, вместе с autowire в hibernate имеет dbutils в качестве зависимости
base: имеет dao в качестве зависимости и имеет те же классы, что и в модели без аннотации (бизнес-объект).
Я использовал Конфигурация на основе Java для автоматического подключения.
Для автоматического подключения dbutils
package org.openrepose.dbutil.spring.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.SessionFactory;
import org.openrepose.dbutil.constants.DbUtilsSpringConfigConstants;
import org.openrepose.dbutil.dbconnection.HibernateUtils;
import org.openrepose.dbutil.hibernateutil.HibernateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
/**
* Spring IoC configuration. This class is responsible for building session
* factory, hibernate util autowire and hibernateutils autowire
*
* @author Nitin gupta (gupta.nitin@snapdeal.com)
*
*/
@Configuration
@PropertySource({ "classpath:persistence-mysql.properties" })
@ComponentScan({ "org.openrepose.dbutil" })
public class DbUtilsSpringConfig {
// autowire environment, properties read form
// classpath:persistence-mysql.properties
@Autowired
private Environment env;
/**
* Build a session factory
*
* @param dataSource
* @return
*/
@Autowired
@Bean(name = DbUtilsSpringConfigConstants.DB_SESSION_FACTORY)
@Scope("singleton")
public SessionFactory getSessionFactory(DataSource dataSource) {
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
sessionBuilder.addProperties(getHibernateProperties());
sessionBuilder.scanPackages("org.openrepose.entities");
return sessionBuilder.buildSessionFactory();
}
/**
* Get The Data Source. Configure all Db related configuration here
*
* @return
*/
@Bean(name = DbUtilsSpringConfigConstants.DB_DATA_SOURCE)
@Scope("singleton")
public DataSource getDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.username"));
dataSource.setPassword(env.getProperty("jdbc.password"));
return dataSource;
}
/**
* get hibernate properties. Configure all hibernate related configuration
*
* @return
*/
public Properties getHibernateProperties() {
return new Properties() {
private static final long serialVersionUID = -4496310006095041101L;
{
setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
setProperty("hibernate.globally_quoted_identifiers",
env.getProperty("hibernate.globally_quoted_identifiers"));
setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
setProperty("hibernate.bytecode.use_reflection_optimizer ",
env.getProperty("hibernate.bytecode.use_reflection_optimizer"));
setProperty("cache.provider_class", env.getProperty("cache.provider_class"));
setProperty("current_session_context_class", env.getProperty("current_session_context_class"));
setProperty("hibernate.globally_quoted_identifiers",
env.getProperty("hibernate.globally_quoted_identifiers"));
}
};
}
/**
* For autowiring Hibernateutil object. Pattern: By constructor
*
* @param sessionFactory
* @return
*/
@Autowired
@Bean(name = DbUtilsSpringConfigConstants.DB_HIBERNATE_UTIL)
@Scope("singleton")
public HibernateUtil getHibernateUtil(SessionFactory sessionFactory) {
return new HibernateUtil(sessionFactory);
}
/**
* For autowiring Hibernateutils object. Pattern: By constructor
*
* @param util
* @return
*/
@Autowired
@Bean(name = DbUtilsSpringConfigConstants.DB_HIBERNATE_UTILS)
@Scope("singleton")
public HibernateUtils getHibernateUtils(HibernateUtil util) {
return new HibernateUtils(util);
}
}
для автоматического подключения Dao
package org.openrepose.dao.model.spring.config;
import org.openrepose.dao.model.constants.DaoSpringConfigConstants;
import org.openrepose.dao.model.implementation.clientauthentication.ClientAuthDAO;
import org.openrepose.dao.model.implementation.clientauthorization.ClientAuthorizationDAO;
import org.openrepose.dao.model.implementation.ipidentity.IpIdentityDAO;
import org.openrepose.dao.model.implementation.quota.QuotaDAO;
import org.openrepose.dao.model.implementation.ratelimit.RatelimitDAO;
import org.openrepose.dao.model.implementation.systemmodel.SystemModelDAO;
import org.openrepose.dao.model.interfaces.IModelDao;
import org.openrepose.dbutil.spring.config.DbUtilsSpringConfig;
import org.openrepose.entities.clientauthentication.ClientAuthConfigEO;
import org.openrepose.entities.clientauthorization.RackspaceAuthorizationConfigEO;
import org.openrepose.entities.ipidentity.IpIdentityConfigEO;
import org.openrepose.entities.quota.QuotaLimitsConfigEO;
import org.openrepose.entities.ratelimit.RateLimitConfigEO;
import org.openrepose.entities.systemmodel.SystemModelConfigEO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;
/**
* Spring IoC configuration. This class is responsible for autowiring the all
* service exposed by Dao layer
*
* @author Nitin gupta (gupta.nitin@snapdeal.com)
*
*/
@Configuration
@ComponentScan({ "org.openrepose.dao" })
@Import(DbUtilsSpringConfig.class)
public class DaoSpringConfig {
@Autowired
@Bean(name = DaoSpringConfigConstants.DAO_CLIENT_AUTH)
@Scope("singleton")
public IModelDao getClientAuth() {
return new ClientAuthDAO();
}
@Autowired
@Bean(name = DaoSpringConfigConstants.DAO_IP_IDENTITY)
@Scope("singleton")
public IModelDao getIpIdentity() {
return new IpIdentityDAO();
}
@Autowired
@Bean(name = DaoSpringConfigConstants.DAO_RATE_LIMIT)
@Scope("singleton")
public IModelDao getRateLimit() {
return new RatelimitDAO();
}
@Autowired
@Bean(name = DaoSpringConfigConstants.DAO_SYSTEM_MODEL)
@Scope("singleton")
public IModelDao getSystemModel() {
return new SystemModelDAO();
}
@Autowired
@Bean(name = DaoSpringConfigConstants.DAO_CLIENT_AUTHORIZATION)
@Scope("singleton")
public IModelDao getClientAuthorization() {
return new ClientAuthorizationDAO();
}
@Autowired
@Bean(name = DaoSpringConfigConstants.DAO_QUOTA)
@Scope("singleton")
public IModelDao getQuotaLimits() {
return new QuotaDAO();
}
}
и для базового автоматического подключения
package org.openrepose.base.spring.config;
import org.openrepose.base.bos.constants.BaseSpringConfigConstants;
import org.openrepose.base.clientauthentication.bos.ClientAuthConfig;
import org.openrepose.base.clientauthentication.service.implementation.ClientAuthBaseImpl;
import org.openrepose.base.clientauthorization.bos.RackspaceAuthorization;
import org.openrepose.base.clientauthorization.service.implementation.ClientAuthorizationBaseImpl;
import org.openrepose.base.conversion.utility.IObjectConverter;
import org.openrepose.base.interfaces.IModelBase;
import org.openrepose.base.ipidentity.bos.IpIdentityConfig;
import org.openrepose.base.ipidentity.service.implementation.IpIdentityBaseImpl;
import org.openrepose.base.quota.bos.Limits;
import org.openrepose.base.quota.service.implementation.QuotaBaseImpl;
import org.openrepose.base.ratelimit.bos.RateLimitingConfiguration;
import org.openrepose.base.ratelimit.service.implementation.RateLimitBaseImpl;
import org.openrepose.base.systemmodel.bos.SystemModel;
import org.openrepose.base.systemmodel.service.implementation.SystemModelBaseImpl;
import org.openrepose.dao.model.spring.config.DaoSpringConfig;
import org.openrepose.entities.clientauthentication.ClientAuthConfigEO;
import org.openrepose.entities.clientauthorization.RackspaceAuthorizationConfigEO;
import org.openrepose.entities.ipidentity.IpIdentityConfigEO;
import org.openrepose.entities.quota.QuotaLimitsConfigEO;
import org.openrepose.entities.ratelimit.RateLimitConfigEO;
import org.openrepose.entities.systemmodel.SystemModelConfigEO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;
/**
* Spring IoC configuration. This class is responsible for autowiring the all
* service exposed by Base layer
*
* @author Nitin gupta (gupta.nitin@snapdeal.com)
*
*/
@Configuration
@ComponentScan({ "org.openrepose.base" })
@Import({DaoSpringConfig.class} )
public class BaseSpringConfig {
@Autowired
@Bean(name = BaseSpringConfigConstants.OBJECT_CONVERTER_CLIENT_AUTH)
@Scope("singleton")
public IObjectConverter getClientAuthConverter() {
return new ClientAuthConfig();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.OBJECT_CONVERTER_CLIENT_AUTHORIZATION)
@Scope("singleton")
public IObjectConverter getRackspaceAuthorizationConverter() {
return new RackspaceAuthorization();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.OBJECT_CONVERTER_IP_IDENTITY)
@Scope("singleton")
public IObjectConverter getIpIdentityConverter() {
return new IpIdentityConfig();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.OBJECT_CONVERTER_QUOTA)
@Scope("singleton")
public IObjectConverter getQuotaConverter() {
return new Limits();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.OBJECT_CONVERTER_RATE_LIMIT)
@Scope("singleton")
public IObjectConverter getRateLimitConverter() {
return new RateLimitingConfiguration();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.OBJECT_CONVERTER_SYSTEM_MODEL)
@Scope("singleton")
public IObjectConverter getSystemModelConverter() {
return new SystemModel();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.BASE_SYSTEM_MODEL)
@Scope("singleton")
public IModelBase getSystemModelBase() {
return new SystemModelBaseImpl();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.BASE_RATE_LIMIT)
@Scope("singleton")
public IModelBase getRateLimitBase() {
return new RateLimitBaseImpl();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.BASE_QUOTA)
@Scope("singleton")
public IModelBase getLimitsBase() {
return new QuotaBaseImpl();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.BASE_IP_IDENTITY)
@Scope("singleton")
public IModelBase getIpIdentityConfigBase() {
return new IpIdentityBaseImpl();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.BASE_CLIENT_AUTH)
@Scope("singleton")
public IModelBase getClientAuthBase() {
return new ClientAuthBaseImpl();
}
@Autowired
@Bean(name = BaseSpringConfigConstants.BASE_CLIENT_AUTHORIZATION)
@Scope("singleton")
public IModelBase getRackspaceAuthorizationBase() {
return new ClientAuthorizationBaseImpl();
}
}
Теперь я пытаюсь проверить, работает ли это автоматическое подключение или нет.
Я проверил до уровня Daos, он работает, используя код ниже
@SuppressWarnings("resource")
AbstractApplicationContext context = new AnnotationConfigApplicationContext(DaoSpringConfig.class);
@SuppressWarnings({ "unchecked", "unused" })
IModelDao c = (IModelDao) context
.getBean(DaoSpringConfigConstants.DAO_CLIENT_AUTH);
НО КОГДА Я ПЫТАЮСЬ СДЕЛАТЬ ТАКОЕ ЖЕ В БАЗОВОМ КЛАССЕ, ЭТО НЕ РАБОТАЕТ (ИСПОЛЬЗУЕТСЯ НИЖЕ КОДА)
@SuppressWarnings("resource")
AbstractApplicationContext context1 = new AnnotationConfigApplicationContext(BaseSpringConfig.class);
@SuppressWarnings({ "unchecked", "unused" })
IObjectConverter c2 = (IObjectConverter) context1
.getBean(BaseSpringConfigConstants.OBJECT_CONVERTER_SYSTEM_MODEL);
ДАЖЕ Если я попытаюсь поместить тот же код, что и на слое dao, в базовый уровень... это не сработает, выдаст исключение выше.
Пожалуйста, помогите, мне действительно нужно это исправить
Базовый пом:
4.0.0
org.openrepose
profile-support
7.1.0.3-SNAPSHOT
repose-config-base
org.glassfish.main.extras
glassfish-embedded-all
3.1.1.2
test
org.springframework
spring-core
org.springframework
spring-context
org.springframework
spring-web
org.springframework
spring-beans
org.springframework
spring-test
org.slf4j
slf4j-api
org.slf4j
jcl-over-slf4j
com.google.guava
guava
org.openrepose
repose-config-models
7.1.0.3-SNAPSHOT
org.openrepose
repose-config-daos
7.1.0.3-SNAPSHOT
org.openrepose
repose-config-catalog
7.1.0.3-SNAPSHOT