简体   繁体   English

春季启动启动错误BOOT-INF /找不到类

[英]spring boot startup error BOOT-INF/classes not found

I have a spring boot project 我有一个春季启动项目

@SpringBootApplication(exclude = {GsonAutoConfiguration.class})
    public class TranslationApplication {
        public static void main(String[] args) {
    SpringApplication.run(TranslationApplication.class, args);
    }
     @Bean
    public LocalEntityManagerFactoryBean entityManagerFactory(){
            LocalEntityManagerFactoryBean factoryBean = new LocalEntityManagerFactoryBean();
           factoryBean.setPersistenceUnitName("CIT_DEV");
    return factoryBean;
    }
}

I use 我用

 EntityManager em = localEntityManagerFactoryBean.getObject().createEntityManager();

to get EntityManager instance 获取EntityManager实例

There is CIT_DEV persistence unit in persistence.xml under META-INF folder 在META-INF文件夹下的persistence.xml中有CIT_DEV持久性单元

I use gradle bootJar to generate jar file, in the jar BOOT-INF/classes/META-INF has persistence.xml 我使用gradle bootJar生成jar文件,在jar BOOT-INF / classes / META-INF中具有persistence.xml

and I use java -jar jarFile to start the spring boot, it throws error 而且我使用java -jar jarFile启动Spring Boot,它会引发错误

at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_40-ea]
 at java.util.zip.ZipFile.(ZipFile.java:220) ~[na:1.8.0_40-ea]
 at java.util.zip.ZipFile.(ZipFile.java:150) ~[na:1.8.0_40-ea]
 at java.util.jar.JarFile.(JarFile.java:166) ~[na:1.8.0_40-ea]
 at java.util.jar.JarFile.(JarFile.java:103) ~[na:1.8.0_40-ea]
 at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.resolveJarFileReference(JarFileBasedArchiveDescriptor.java:168) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:51) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:47) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:76) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:99) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.(EntityManagerFactoryBuilderImpl.java:232) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.(EntityManagerFactoryBuilderImpl.java:174) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50) [hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) [javaee-api-8.0.jar!/:na]
 at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:96) [spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) [spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) [spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$87/1170794006.getObject(Unknown Source) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$87/1170794006.getObject(Unknown Source) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) [spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) [spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) [spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) [spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
 at oracle.cit.translation.TranslationApplication.main(TranslationApplication.java:18) [classes!/:na]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40-ea]
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40-ea]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40-ea]
 at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40-ea]
 at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [cit-trans-microservice-1.0.jar:na]
 at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [cit-trans-microservice-1.0.jar:na]
 at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [cit-trans-microservice-1.0.jar:na]
 at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [cit-trans-microservice-1.0.jar:na]

Just use: 只需使用:

@Autowired
EntityManager em;

It's managed by springboot. 它由springboot管理。

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html

Spring Boot will not search for or use a META-INF/persistence.xml by default. 默认情况下,Spring Boot不会搜索或使用META-INF / persistence.xml。 If you prefer to use a traditional persistence.xml, you need to define your own @Bean of type LocalEntityManagerFactoryBean (with an ID of 'entityManagerFactory') and set the persistence unit name there. 如果您更喜欢使用传统的persistence.xml,则需要定义自己的LocalBeanManagerFactoryBean类型的@Bean(ID为'entityManagerFactory')并在其中设置持久性单元名称。

I use this way, but it still has the filenotfound exception 我使用这种方式,但是它仍然有filenotfound异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot java项目中的/ BOOT-INF / classes(没有这样的文件或目录) - /BOOT-INF/classes (No such file or directory) on spring boot java project 从BOOT-INF / classes中读取文件 - Read files from BOOT-INF/classes Spring Boot Maven 插件 - 没有 BOOT-INF 目录 - Spring Boot Maven Plugin - No BOOT-INF directory spring-boor jar 中的 BOOT-INF 和 META-INF 目录是什么? - What are the BOOT-INF and META-INF directories in spring-boor jar? Spring引导微服务jar BOOT-INF将类加载器资源作为流到'Null'的流 - Class loader resource as stream to 'Null', Spring boot microservice jar BOOT-INF 如何从spring-boot jar BOOT-INF \\ lib文件夹中提取文件 - how to extract a file from spring-boot jar BOOT-INF\lib folder 无法导入类,IntelliJ 显示 BOOT-INF 前缀,似乎是相关的 - Can't import classes, IntelliJ showing BOOT-INF prefix and it seems to be related 从资源中读取文件 - 路径必须存在:/app/app.jar!/BOOT-INF/classes!/features/ - Reading file from resource - path must exist: /app/app.jar!/BOOT-INF/classes!/features/ 从 1.5.8 到 2.1.14-RELEASE 的 spring boot 迁移后,BootJar 没有创建 BOOT-INF 文件夹 - BootJar didn't create BOOT-INF folder after spring boot migration from 1.5.8 to 2.1.14-RELEASE SBT+spring-boot:“在 META-INF/spring.factories 中找不到自动配置类” - SBT+spring-boot: “ No auto configuration classes found in META-INF/spring.factories”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM