我在sprint-boot
部署.war
应用程序(已转换tp liberty 8.5
)时遇到问题:
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"
但是当我运行我的spring-boot
应用程序打包为.jar
时,它可以正常工作。
我的坚持是
<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>
类数据库配置
@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:
<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>
答案 0 :(得分:0)
尝试先更改为parent,这样,类加载器将从自由(应用服务器)加载,然后您的应用将覆盖已加载的类。
<application location="...">
<classloader delegation="**parentFirst**" privateLibraryRef="...." />
</application>
参考: