2017-04-27 34 views
1
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoB2a': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
    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:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140) 
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84) 
    at test.Main.main(Main.java:28) 
Caused by: java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
    at org.springframework.data.mapping.PropertyReferenceException.detectPotentialMatches(PropertyReferenceException.java:134) 
    at org.springframework.data.mapping.PropertyReferenceException.<init>(PropertyReferenceException.java:59) 
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75) 
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) 
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) 
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) 
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) 
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) 
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235) 
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) 
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353) 
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:87) 
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:61) 
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95) 
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:206) 
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:73) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:416) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) 
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) 
    ... 12 more 

@Component("test") 
public class JpaConfig { 

@Autowired 
daoB2a dao; 

public daoB2a getDao() { 
    return dao; 
} 

public void setDao(daoB2a dao) { 
    this.dao = dao; 
} 



} 

<jpa:repositories base-package="com.company.springdata.daos" /> 
<context:property-placeholder location="src/main/resources/application.properties"/> 

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="${db.drivermanager}"/> 
    <property name="url" value="${db.url}"/> 
    <property name="password" value="${db.password}"/> 
    <property name="username" value="${db.username}"/> 
</bean> 

<bean id="hbAdapterBean" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
    <property name="showSql" value="true"/> 
    <property name="generateDdl" value="true"/> 
    <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/> 
</bean> 

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="packagesToScan" value="com.mycompany.springdata.entities"/> 
    <property name="jpaVendorAdapter" ref="hbAdapterBean"/> 
</bean> 

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory" /> 
</bean> 

<context:component-scan base-package="com.mycompany.springdata.entities"/> 



public class Main { 

public static void main(String[] args) { 
    ApplicationContext app = new FileSystemXmlApplicationContext("src/main/resources/beans.xml"); 
    System.out.println("read successfuly"); 

    //  JpaConfig user = (JpaConfig) app.getBean("test"); 
    //  System.out.println("user is "+user); 
    // System.out.println(""+user.getDao().save(new User("dskds", "sds",   "dsds", "dsddskd"))); 

} 
} 
+0

如果您希望得到答案,请提出问题会有所帮助。也http://stackoverflow.com/help/how-to-ask –

+0

谢谢你的帮助:) –

回答

0

确保您在xml文件中注入了daoB2a bean ;

+0

@Component(“test”) public class JpaConfig {} –