创建entityManagerFactory时出错,因为绑定错误需要扫描< jar-file> [英] Error creating entityManagerFactory due to error tying to scan <jar-file>
问题描述
我遵循 http://spring.io/guides/tutorials/data/3;我不是
,确定我做错了什么,但是我继续收到我不明白的例外。我尝试搜索相同例外的问题无济于事。
堆栈跟踪:
http://pastebin.com/WYPqS6da
PersistenceConfig.java
@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
public class PersistenceConfig {
@Bean
public DataSource dataSource()throws SQLException {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
返回builder.setType(EmbeddedDatabaseType.HSQL).build();
$ b $Be
public EntityManagerFactory entityManagerFactory()throws SQLException {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.HSQL);
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan(com.scrumster.persistence.domain);
factory.setDataSource(dataSource());
factory.afterPropertiesSet();
返回factory.getObject();
}
@Bean
public EntManagerManager entityManager(EntityManagerFactory entityManagerFactory){
return entityManagerFactory.createEntityManager();
$ b $Be
public PlatformTransactionManager transactionManager()throws SQLException {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory());
返回txManager;
$Be
public HibernateExceptionTranslator hibernateExceptionTranslator(){
return new HibernateExceptionTranslator();
}
}
build.gradle:
apply plugin:'war'
apply plugin:'tomcat'
apply plugin:'java'
apply plugin: 'propdeps'
apply plugin:'propdeps-maven'
apply plugin:'propdeps-idea'
apply plugin:'propdeps-eclipse'
apply plugin:'eclipse'
apply plugin:'idea'
buildscript {
repositories {
mavenCentral()
maven {
urlhttp:// download。 java.net/maven/2
}
maven {url'http://repo.spring.io/plugins-release'}
}
依赖关系{
classpath'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.8'
classpath'org.springframework.build.gradle:propdeps-plugin:0.0.1'
}
}
存储库{
mavenCentral()
maven {url'http://repo.spring.io/milestone/'}
}
依赖关系{
def tomcatVersion ='7.0.42
tomcatorg.apache.tomcat.embed:tomcat-embed-core:$ {tomcatVersion},
org.apache.tomcat.embed:tomcat-embed-logging-juli:$ {tomcatVersion }
tomcat(org.apache.tomcat.embed:tomcat-embed-jasper:$ {tomcatVersion}){
exclude group:'org.eclipse.jdt.core.compiler',module :'ecj'
}
compile'org.springframework:spring-webmvc:4.0.5.RELEASE'
compile'org.springframework.data:spring-data-jpa :1.3.4.RELEASE'
compile'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
compile'org.hibernate:hibernate-entitymanager:4.0 .1.Final'
compile'org.springframework.hateoas:spring-hateoas:0.7.0.RELEASE'
compile'com.jayway.jsonpath:json-path:0.8.1'
compile'org.springframework.security:spring-security-web:3.2.0.M2'
compile'org.springframework.security:spring-security-core:3.2.0.M2'
编译'org.springfram ework.security:spring-security-config:3.2.0.M2'
compile'org.slf4j:slf4j-api:1.7.5'
runtime'org.hsqldb:hsqldb: 2.3.2'
runtime'org.slf4j:slf4j-jdk14:1.7.5'
runtime'com.fasterxml.jackson.core:jackson-databind:2.3.3'
runtime' javax.xml.bind:jaxb-api:2.2.9'
提供'javax.servlet:javax.servlet-api:3.0.1'
testCompile'com。 jayway.jsonpath:json-path-assert:0.8.1'
testCompile'org.springframework:spring-test:4.0.5.RELEASE'
testCompile'junit:junit:4.11'
testCompileorg.mockito:mockito-core:1.9.5
}
任务包装(类型:Wrapper){
gradleVersion ='1.12'
tomcatRunWar.contextPath =''
Stacktrace: p>
导致:java.lang.RuntimeException:读取文件时出错:/ E:/ Files / Source / Workspace -Eclipse2 / scrumster / bin /
在org.hibern ate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:193)
位于org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:503)
位于org.hibernate.ejb.Ejb3Configuration。 scanForClasses(Ejb3Configuration.java:851)
... 58 more
导致:java.io.IOException:无效的常量类型:18
at javassist.bytecode.ConstPool.readOne(ConstPool。 java:1113)
at javassist.bytecode.ConstPool.read(ConstPool.java:1056)
at javassist.bytecode.ConstPool。< init>(ConstPool.java:150)
at javassist.bytecode.ClassFile.read(ClassFile.java:765)
at javassist.bytecode.ClassFile。< init>(ClassFile.java:109)
我希望有人能指点我正确的来源,或者帮助我解决这个困境。 方案
错误:
无效常量类型:18
表示t您已经用Java 8构建了Jars,但正试图以较低版本运行该应用程序。
从我在别处看到的情况来看,您可能需要切换到一个更新版本的javassist(这会引发错误),因为您使用的版本与Java 8不兼容。
I am following http://spring.io/guides/tutorials/data/3 ; I am not sure what I did wrong, but I keep on getting exceptions that I don't understand. I tried searching for questions with the same exceptions to no avail.
Stack trace: http://pastebin.com/WYPqS6da
PersistenceConfig.java
@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
public class PersistenceConfig {
@Bean
public DataSource dataSource() throws SQLException {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL).build();
}
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.HSQL);
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("com.scrumster.persistence.domain");
factory.setDataSource(dataSource());
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
return entityManagerFactory.createEntityManager();
}
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory());
return txManager;
}
@Bean
public HibernateExceptionTranslator hibernateExceptionTranslator() {
return new HibernateExceptionTranslator();
}
}
build.gradle:
apply plugin: 'war'
apply plugin: 'tomcat'
apply plugin: 'java'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
apply plugin: 'eclipse'
apply plugin: 'idea'
buildscript {
repositories {
mavenCentral()
maven {
url "http://download.java.net/maven/2"
}
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.8'
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.1'
}
}
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/milestone/'}
}
dependencies {
def tomcatVersion = '7.0.42'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
compile 'org.springframework:spring-webmvc:4.0.5.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.3.4.RELEASE'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
compile 'org.hibernate:hibernate-entitymanager:4.0.1.Final'
compile 'org.springframework.hateoas:spring-hateoas:0.7.0.RELEASE'
compile 'com.jayway.jsonpath:json-path:0.8.1'
compile 'org.springframework.security:spring-security-web:3.2.0.M2'
compile 'org.springframework.security:spring-security-core:3.2.0.M2'
compile 'org.springframework.security:spring-security-config:3.2.0.M2'
compile 'org.slf4j:slf4j-api:1.7.5'
runtime 'org.hsqldb:hsqldb:2.3.2'
runtime 'org.slf4j:slf4j-jdk14:1.7.5'
runtime 'com.fasterxml.jackson.core:jackson-databind:2.3.3'
runtime 'javax.xml.bind:jaxb-api:2.2.9'
provided 'javax.servlet:javax.servlet-api:3.0.1'
testCompile 'com.jayway.jsonpath:json-path-assert:0.8.1'
testCompile 'org.springframework:spring-test:4.0.5.RELEASE'
testCompile 'junit:junit:4.11'
testCompile "org.mockito:mockito-core:1.9.5"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
tomcatRunWar.contextPath = ''
Stacktrace:
Caused by: java.lang.RuntimeException: Error while reading file:/E:/Files/Source/Workspace-Eclipse2/scrumster/bin/
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:193)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:503)
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:851)
... 58 more
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1113)
at javassist.bytecode.ConstPool.read(ConstPool.java:1056)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:150)
at javassist.bytecode.ClassFile.read(ClassFile.java:765)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:109)
I hope someone could point me to the right source, or help me in this predicament.
The error:
invalid constant type: 18
Indicates that you have built the Jars with Java 8, but are attempting to run the application in a lower version.
From what I have seen elsewhere, you probably need to switch to a newer version of javassist (which is raising the error), as the version you are using is not compatible with Java 8.
这篇关于创建entityManagerFactory时出错,因为绑定错误需要扫描< jar-file>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!