首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套异常为java.lang.LinkageError:违反加载器约束

嵌套异常为java.lang.LinkageError:违反加载器约束
EN

Stack Overflow用户
提问于 2017-06-23 01:55:04
回答 1查看 1.4K关注 0票数 0

liberty 8.5中部署我的sprint-boot应用程序(转换为tp .war)时遇到问题

代码语言:javascript
复制
Failed to instantiate [javax.persistence.EntityManager]: 
Factory method 'createSharedEntityManager' threw exception; 
nested exception is java.lang.LinkageError: loader constraint violation:
loader (instance of com/ibm/ws/classloading/internal/ThreadContextClassLoader)
previously initiated loading for a different type with name
"org/eclipse/persistence/expressions/Expression"

但是,当我运行打包为.jarspring-boot应用程序时,它可以正常工作。

我的坚持是

代码语言:javascript
复制
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 

    version="2.0">

<persistence-unit name="authentication"
    transaction-type="RESOURCE_LOCAL">
    <provider>
        org.eclipse.persistence.jpa.PersistenceProvider
    </provider>

    <class>
        com.bank.arc.commons.entity.AuthenticationEntity
    </class>

    <properties>
        <property name="eclipselink.weaving" value="static" />
        <property name="eclipselink.target-server" value="WebSphere_Liberty" 
            /> 
        <property name="eclipselink.target-database"
        value="org.eclipse.persistence.platform.database.DB2Platform" />
        <property name="eclipselink.logging.level" value="WARNING" />

    </properties>

</persistence-unit>

类数据库配置

代码语言:javascript
复制
@Configuration
@EnableTransactionManagement
@EnableConfigurationProperties(DbAuthenticationProperties.class)
@EnableJpaRepositories(basePackages = {"com.bank.arc.commons.dao.repository"}, 
entityManagerFactoryRef = "authenticationDbEntityManagerFactory", 
transactionManagerRef = "authenticationDbTransactionManager")


public class DbAuthenticationConfig extends DbConfig {

@Autowired
private DbAuthenticationProperties  properties;

@PostConstruct
public void init() {
    super.setProperties(properties);
}

@Bean
@Primary
public DataSource authenticationDbDataSource() {
    return super.dataSource();
}

@Bean
@Primary
public LocalContainerEntityManagerFactoryBean authenticationDbEntityManagerFactory() {
    return super.entityManagerFactoryBean(authenticationDbDataSource(), authenticationDbJpaVendorAdapter(), "authentication");
}

@Bean
@Primary
protected JpaVendorAdapter authenticationDbJpaVendorAdapter() {
    return super.jpaVendorAdapter(DatabasePlatform.DB2);
}

@Bean
@Primary
protected PlatformTransactionManager authenticationDbTransactionManager() {
    return super.transactionManager(authenticationDbEntityManagerFactory());
}

}

和server.xml:

代码语言:javascript
复制
<server description="new server">

<featureManager>
    <feature>localConnector-1.0</feature>
    <feature>jdbc-4.1</feature>
    <feature>servlet-3.1</feature>
    <feature>jpa-2.1</feature>
</featureManager>

<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>

<jpa defaultPersistenceProvider="org.eclipse.persistence.jpa.PersistenceProvider" ignoreDataSourceErrors="true"/> 

<applicationMonitor updateTrigger="mbean"/>

<webApplication id="authentication-endpoint" location="authentication-endpoint.war" name="authentication-endpoint"/>
</server>
EN

回答 1

Stack Overflow用户

发布于 2018-10-21 21:57:57

尝试更改为parentfirst,这样类加载器将从liberty (应用程序服务器)加载,然后您的应用程序将覆盖加载的类。

代码语言:javascript
复制
 <application location="...">
   <classloader delegation="**parentFirst**" privateLibraryRef="...." />
 </application>

参考:

https://www.ibm.com/support/knowledgecenter/en/SSAW57_9.0.0/com.ibm.websphere.nd.multiplatform.doc/ae/urun_rclassloader_inst.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44706349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档