我们使用Spring和hibernate数据库映射。实体包含JSON列,映射为使用package-info.java文件定义的自定义类型。
当我们从Eclipse运行spring项目时,一切正常,我们可以调用我们的web服务。
当我们生成一个可执行的jar并试图调用我们的web服务时,会引发以下错误:
mai 04, 2017 1:35:00 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Unable to execute job Test] with root cause
java.lang.NoClassDefFoundError: BOOT-INF/classes/com/test/package-info (wrong name: com/test/package-info)
at java.lang.ClassLoader.defineClass1(Native Method)文件包-info.class进入了jar引导-INF/classes/com/test/package-info,有什么问题吗?
谢谢你的帮助
发布于 2017-10-19 19:45:05
我通过禁用包扫描和Hibernate类的自动检测来解决这个问题。
<persistence-unit name="sqlProvider" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.example.package.dao</class>
.........
<properties>
<property name="exclude-unlisted-classes" value="true"/>
<property name="hibernate.archive.autodetection" value="hbm" />
.........
</properties>
.........
</persistence-unit>发布于 2018-01-30 13:44:56
我不想禁用扫描,因为手动将所有类添加到persistence.xml并不是一个选项。由于我们在我们的项目中实际上并没有对hibernate使用包级注释,所以我创建了这个小小的令人厌恶的东西:
package com.example;
import org.hibernate.boot.archive.scan.internal.ScanResultImpl;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
public class HibernateHackScanner extends StandardScanner {
private static final Logger log = LoggerFactory.getLogger(HibernateHackScanner.class);
@Override
public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) {
log.info("Hack-Scanner is active, annotated packages will not be found by this scanner.");
ScanResult scan = super.scan(environment, options, parameters);
return new ScanResultImpl(Collections.emptySet(), scan.getLocatedClasses(), scan.getLocatedMappingFiles());
}
}然后我在persistence.xml中启用了这个自定义扫描器。
<property name="hibernate.archive.scanner" value="com.example.HibernateHackScanner"/>这个扫描仪使用引擎盖下的标准扫描器,简单地丢弃所有带有boot_inf.classes等的带注释的包。但是,如果您实际上需要包级注释,则需要比这个拐杖更复杂一些。但是这对我来说是有效的,¯\_(ツ)_/
发布于 2019-09-11 15:08:25
Nestor Fedyk解决方案帮助我解决了这个问题。
请找到下面的代码,我已经将解决方案添加到了hibernate配置文件中。
添加了"hibernate.archive.autodetection"属性“排除-未列出-类”
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="rcsDataSource"/>
<property name="persistenceUnitName" value="corePersistenceUnit"/>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.region.factory_class">xxxx.xxxxxxxx.xxxx</prop>
<prop key="hibernate.cache.provider_class">xxx.xxxxxxxx.xxxx</prop>
<prop key="hibernate.cache.use_structured_entries">false</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.default_batch_fetch_size">250</prop>
<prop key="hibernate.max_fetch_depth">5</prop>
<prop key="hibernate.jdbc.fetch_size">300</prop>
<prop key="exclude-unlisted-classes">true</prop>
<prop key="hibernate.archive.autodetection">"hbm"</prop>
</props>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>我希望这能帮到你
https://stackoverflow.com/questions/43782191
复制相似问题