0

I have a trouble deploying my sprint-boot application (converted tp .war) in 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"

But when I run my spring-boot application packaged as .jar it works.

My persistence is

<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>

Class Database Config

@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());
}

}

And the 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>
gpalacios
  • 1
  • 2
  • Do you have a copy of eclipselink packaged in your application? If so, you that's probably not necessary because the `jpa-2.1` feature will provide it for you. Currently the two copies are probably conflicting with each other. – Andy Guibert Jun 22 '17 at 20:06
  • @AndyGuibert Update the files at the top, even though I removed the featured jpa-2.1 in `server.xml`, reappeared when running the liberty. – gpalacios Jun 22 '17 at 21:07
  • it is correct the cause is JPA-2.1, there are remove it of server.xml, thanks – gpalacios Jun 22 '17 at 22:02
  • instead of disabling the jpa-2.1 feature in server.xml another option would be to remove eclipselink from your app. Glad you got it working though – Andy Guibert Jun 22 '17 at 22:03

1 Answers1

0

try to change to parentfirst, so classloader will load from liberty (app server) then you app will override the loaded classes.

 <application location="...">
   <classloader delegation="**parentFirst**" privateLibraryRef="...." />
 </application>

Ref:

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

Mohamed.Abdo
  • 2,054
  • 1
  • 19
  • 12