Glassfish embedded Fails to deploy EJB modules - java

Does somebody can help me to solve this error with JUnit4.12 and glassfish4.1?
I'm trying to test EJB using JUnit but I got this message from JUnit trace:
javax.ejb.EJBException: Failed to deploy EJB modules - see log for details
at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:149)
Using maven my pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.leorm.sga</groupId>
<artifactId>sga-jee-last</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<glassfish.embedded-static-shell.jar>
/opt/servers/glassfish4/glassfish/lib/embedded/glassfish-embedded-static-shell.jar
</glassfish.embedded-static-shell.jar>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
My JUnit test case is:
...
public class PersonaServiceTest {
private PersonaService personaService;
#Before
public void setUp() throws NamingException{
EJBContainer contenedor = EJBContainer.createEJBContainer();
personaService = (PersonaService) contenedor.getContext().lookup("ejb/Persona");
}
#Test
public void test() {
System.out.println("Starting test EJB PersonaService");
assertTrue(personaService != null);
assertEquals(2, personaService.listarPersonas().size());
System.out.println("Count personas is:" + personaService.listarPersonas().size());
this.desplegarPersonas(personaService.listarPersonas());
System.out.println("End test EJB PersonaService");
}
private void desplegarPersonas(List<Persona> personas) {
for(Persona persona: personas){
System.out.println(persona);
}
}
}
The console says:
INFO: [EJBContainerImpl] GlassFish status: STARTED
Oct 18, 2015 11:33:56 AM org.glassfish.ejb.embedded.EJBContainerImpl deploy
INFO: [EJBContainerImpl] Deploying as a ScatteredArchive
Oct 18, 2015 11:33:57 AM org.glassfish.deployment.common.GenericAnnotationDetector scanArchive
WARNING: NCLS-DEPLOYMENT-00009
Oct 18, 2015 11:33:57 AM org.glassfish.api.ActionReport failure
SEVERE: Archive type of /tmp/classes.jar was not recognized
Oct 18, 2015 11:33:57 AM org.glassfish.ejb.embedded.EJBContainerProviderImpl createEJBContainer
INFO: [EJBContainerProviderImpl] Cleaning up on failure ...
JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool]
Oct 18, 2015 11:33:57 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
Oct 18, 2015 11:33:57 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool]
Oct 18, 2015 11:33:57 AM com.sun.enterprise.v3.server.AppServerStartup stop
INFO: Shutdown procedure finished

My personal experience with running such test in eclipse as a standalone JUnit (not via maven test) is to use overloaded version of createEJBContainer, in which developer has to specify where to find the compiled bean classes. Assuming EJB classes are located in {currentProject}/target/classes and are using EJB annotations the following solved the same issue for me:
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EJBContainer.MODULES, new File("target/classes"));
ec = EJBContainer.createEJBContainer(properties);

Related

Java-Selenium- Unable to find an exact match for CDP version 98, so returning the closest version found: 97

I have created a maven project for taking a screenshot from the webpage URL which I have given in my code. I am using chrome driver version 98 and selenium version 4.1.2. I'm getting a warning message with the CDP versions when running my code.
Here is my code.
TakeScreenshot.java
public class Takescreenshot
{
private static final File SrcnewFile = null;
public static void main(String[] args) throws Exception
{
WebDriver driver ;
WebDriverManager.chromedriver().clearCache();
//System.setProperty("webdriver.chrome.driver","C:\drivers/chromedriver.exe");
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://www.amazon.in/");
TakesScreenshot scrShot =((TakesScreenshot)driver);
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
if(null!=null)
{
File DestFile=new File("c:test/test1.png");
FileUtils.copyFile(SrcFile, DestFile);
FileUtils.getFile(SrcnewFile, ("c://test1.png"));
driver.quit();
}
}
}
When I try to run my program the following error shows up.
Starting ChromeDriver 98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758#{#972}) on port 58811
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Feb 15, 2022 12:53:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Feb 15, 2022 12:53:33 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 98, so returning the closest version found: 97
Feb 15, 2022 12:53:33 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 98 of 97
I'm using Maven. My pom.xml file looks like this
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
</dependency>
When I run the java program the chrome browser will open and the page is loaded, but the screenshot of the page is not generating and couldn't be saved in the local machine. Could anyone please help me to resolve it?
Please using following code:
TakesScreenshot scrShot =((TakesScreenshot)driver);
File srcFile = scrShot.getScreenshotAs(OutputType.FILE);
if(srcFile != null)
{
File saveFileName = new File("test1.png");
FileHandler.copy(srcFile, saveFileName);
}

Maven Project Hibernate, MySQL connection problem

I am using Intelij idea and I am tying to make a simple connection with MySQL database with hibernate following a YouTube video.
For some reason my connection does not work and I get the following Errors:
Mar 30, 2021 12:04:31 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.4.30.Final
Mar 30, 2021 12:04:31 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
Mar 30, 2021 12:04:31 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
Mar 30, 2021 12:04:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Mar 30, 2021 12:04:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/calculator?autoReconnect=true&useSSL=false]
Mar 30, 2021 12:04:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, user=root}
Mar 30, 2021 12:04:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Mar 30, 2021 12:04:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Mar 30, 2021 12:04:36 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata
java.lang.IllegalStateException: Cannot get a connection as the driver manager is not properly initialized
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:172)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:116)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.addConnections(DriverManagerConnectionProviderImpl.java:341)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init>(DriverManagerConnectionProviderImpl.java:260)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init>(DriverManagerConnectionProviderImpl.java:238)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections$Builder.build(DriverManagerConnectionProviderImpl.java:379)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:98)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:86)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:479)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.example.App.main(App.java:25)
Mar 30, 2021 12:04:36 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Mar 30, 2021 12:04:36 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08001
Mar 30, 2021 12:04:36 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Hello World!
Process finished with exit code 0
I am using zulu16.28.11 as my JDk, and MySQL WorkBench 8 .
From Idea I tested my connections and seems okay
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DemoHib</artifactId>
<version>1.0-SNAPSHOT</version>
<name>DemoHib</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.30.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/calculator?autoReconnect=true&useSSL=false</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
</session-factory>
</hibernate-configuration>
Alien.java (my class)
package org.example;
import javax.persistence.Entity;
import javax.persistence.Id;
#Entity
public class Alien {
#Id
private int aid;
private String name;
private String pass;
public int getAid() {
return aid;
}
public String getName() {
return name;
}
public String getPass() {
return pass;
}
public void setAid(int aid) {
this.aid = aid;
}
public void setName(String name) {
this.name = name;
}
public void setPass(String pass) {
this.pass = pass;
}
}
App.java
package org.example;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class App
{
public static void main( String[] args )
{
Alien telusko = new Alien();
telusko.setAid(101);
telusko.setName("Matheos");
telusko.setPass("564");
Configuration con = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Alien.class);
try{
SessionFactory sf = con.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(telusko);
tx.commit();
}
catch (Exception e){
System.out.println(e);
}
//SessionFactory sf = con.buildSessionFactory();
System.out.println( "Hello World!" );
}
}
I tried to find a solution for my problem online but I didnt find something to apply to my problem.
My problem was with the MySQL dependency I changed it to version 8.0.16 and worked.
I had this problem today too, I upgraded the package of mysql-connector-java for 8.0.23 and it worked fine.

Spring AOP pointcut expression method with 0 or more argument of any type throws java.lang.NullPointerException

I'm following a tutorial where I'm trying to use a Spring AOP pointcut expression method that accepts 0 or more arguments of any type but I'm getting a java.lang.NullPointerException.
I am using Spring MVC and maven along with eclipse.
Everything is working fine if I use:
#Before("execution(* add*())")
or
#Before("execution(* add*(*))")
or
#Before("execution(* add*(boolean,..))")
but the moment I use ".." alone
#Before("execution(* add*(..))")
to mean that I want that the pointcut expression matches a method with 0 or more arguments of any type, when I try to access to my view using the following URL: http://localhost:8080/springaopdemo/main/test
I get HTTP Status 500 - Internal Server Error
and in my eclipse console log, I get the following error:
Thank you in advance for your help
Direct link to project in case you need it: https://github.com/odamak/springaopdemo/commit/cfbfef8ac80cd1c88b9a9359bbba964503cc24c5
INFO: Initializing Spring DispatcherServlet 'dispatcher'
Jan 05, 2020 8:31:51 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: Initializing Servlet 'dispatcher'
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final org.springframework.web.servlet.HandlerExecutionChain org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(javax.servlet.http.HttpServletRequest) throws java.lang.Exception] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractHttpMessageConverter.write(java.lang.Object,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.http.converter.AbstractHttpMessageConverter.read(java.lang.Class,org.springframework.http.HttpInputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotReadableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractHttpMessageConverter.write(java.lang.Object,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.http.converter.AbstractHttpMessageConverter.read(java.lang.Class,org.springframework.http.HttpInputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotReadableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractHttpMessageConverter.write(java.lang.Object,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.http.converter.AbstractHttpMessageConverter.read(java.lang.Class,org.springframework.http.HttpInputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotReadableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(java.lang.Object,java.lang.reflect.Type,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractHttpMessageConverter.write(java.lang.Object,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.http.converter.AbstractHttpMessageConverter.read(java.lang.Class,org.springframework.http.HttpInputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotReadableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractHttpMessageConverter.write(java.lang.Object,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:54 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.http.converter.AbstractHttpMessageConverter.read(java.lang.Class,org.springframework.http.HttpInputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotReadableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:55 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final void org.springframework.http.converter.AbstractHttpMessageConverter.write(java.lang.Object,org.springframework.http.MediaType,org.springframework.http.HttpOutputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotWritableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:55 AM org.springframework.aop.framework.CglibAopProxy doValidateClass
INFO: Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.http.converter.AbstractHttpMessageConverter.read(java.lang.Class,org.springframework.http.HttpInputMessage) throws java.io.IOException,org.springframework.http.converter.HttpMessageNotReadableException] because it is marked as final: Consider using interface-based JDK proxies instead!
Jan 05, 2020 8:31:55 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: Completed initialization in 4385 ms
Jan 05, 2020 8:31:55 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Jan 05, 2020 8:31:55 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Jan 05, 2020 8:31:55 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11176 ms
Jan 05, 2020 8:32:08 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/springaopdemo] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:408)
at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1234)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1016)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Here is the definition of the Aspect:
package com.luv2code.aopdemo.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
#Aspect
#Component
public class MyDemoLoggingAspect {
#Before("execution(* add*(..))")
public void beforeAddAccountAdvice() {
System.out.println("\n======>>> Executing #Before advice on method");
}
}
Here is a definition of one of the classes that has a method on which #Before advice is supposed to be applied:
package com.luv2code.aopdemo.dao;
import org.springframework.stereotype.Component;
#Component
public class MembershipDAO {
public void addAccount() {
System.out.println(getClass() + ": DOING MY DB WORK: ADDING A MEMBERSHIP ACCOUNT");
}
}
Here is my config class:
package com.luv2code.aopdemo;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
#Configuration
#EnableAspectJAutoProxy
#ComponentScan("com.luv2code.aopdemo")
public class DemoConfig {
}
Here is the Controller that makes use of the method on which the advice is applied:
package com.luv2code.aopdemo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.luv2code.aopdemo.dao.AccountDAO;
import com.luv2code.aopdemo.dao.MembershipDAO;
#Controller
#RequestMapping("/main")
public class MainController {
#GetMapping("/test")
public String MainTest() {
System.out.println("hello from /main/test");
// read spring config java class
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DemoConfig.class);
// get the bean from spring container
theMembershipDAO = context.getBean("membershipDAO", MembershipDAO.class);
// call the membership business method
theMembershipDAO.addAccount();
// close the context
context.close();
return "main-test";
}
}
Here is my view:
<html>
<body>
<h2>Hello World from main-test!</h2>
</body>
</html>
Here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-aop-demo</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-aop-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Here is spring-aop-demo-servlet.xml config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Add AspectJ autoproxy support for AOP -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- Add support for component scanning -->
<context:component-scan
base-package="com.luv2code.aopdemo" />
<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven />
<!-- Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Add support for reading web resources: css, images, js, etc ... -->
<mvc:resources location="/resources/"
mapping="/resources/**"></mvc:resources>
</beans>
Here is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.luv2code</groupId>
<artifactId>springaopdemo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springaopdemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>5.2.0.RELEASE</org.springframework-version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate-version>5.4.7.Final</hibernate-version>
<aspectj-version>1.9.5</aspectj-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springaopdemo</finalName>
</build>
</project>
Your pointcut is too global. You are trying to weave into too many classes, specifically Spring core classes. Try to limit pointcut matching to your own application packages via within(com.luv2code.aopdemo..*). See my other answer for other sample pointcuts.

Continuously getting java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener

I am struggling to solve the below exception:
INFO: No Spring WebApplicationInitializer types detected on classpath
Apr 17, 2017 8:48:01 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.apache.tomcat.util.descriptor.web.ApplicationListener#1e856aa
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1465)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1310)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:531)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:513)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:141)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4756)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5288)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1390)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1380)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Apr 17, 2017 8:48:01 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Apr 17, 2017 8:48:01 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
I am using maven and added below dependency to solve this but not getting result, still facing same issue.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
I already added the maven dependency. For Spring and Hibernate I have added all the required dependency.
If the error is saying that the class is not found, then it's actually saying that the class can not be loaded by the JVM, because the JVM can not find that class in your classpath.
Then you need to build your project again with maven, in order to create .class files for your JVM,
Or before that, try to pull again your project dependencies from remote maven repository into your local maven repository, and then do the maven build project in order to populate .class files.
Hope that this helps.
I think the problem is not on your dependencies. I am new to spring too but i think this might help you:
#Configuration
public class SpringWebAppInitializer implements WebApplicationInitializer{
#Override
public void onStartup(ServletContext sc) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(ApplicationContextConfig.class);
ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}

Maven 3.2.1 + Hibernate 4.3.4 - Unable to build entity manager factory - Caused by: ParameterizedTypeImpl cannot be cast to java.lang.Class

I have migrated a Hibernate 4.3.4 to a Maven 3.2.1 project. I have created just one jar file with maven-shade-plugin, but when I start it I have the following exception:
Mar 17, 2014 10:44:35 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Mar 17, 2014 10:44:35 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Mar 17, 2014 10:44:35 AM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Mar 17, 2014 10:44:35 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: MfsDao
...]
Mar 17, 2014 10:44:36 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.4.Final}
Mar 17, 2014 10:44:36 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Mar 17, 2014 10:44:36 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Mar 17, 2014 10:44:44 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:81)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at de.cegelec.vwezlt.mfs.dao.MfsEntityManager.getEntityManagerFactory(MfsEntityManager.java:117)
at de.cegelec.vwezlt.mfs.dao.MfsEntityManager.getMfsEntityManager(MfsEntityManager.java:25)
at de.cegelec.vwezlt.mfsvert.main.MfsVert.main(MfsVert.java:168)
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
at org.hibernate.cfg.AttributeConverterDefinition.<init>(AttributeConverterDefinition.java:67)
at org.hibernate.cfg.Configuration.addAttributeConverter(Configuration.java:2690)
at org.hibernate.cfg.Configuration.addAttributeConverter(Configuration.java:2641)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1129)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:73)
I have debugged and I have found that the class which raises the exception is org.apache.logging.log4j.core.appender.db.jpa.converter.ContextMapAttributeConverter.
In my pom I have a dependency with log4j 2.0-rc1 as dependency:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-rc1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-rc1</version>
</dependency>
It has worked fine before I tried to integrate all in Maven.
Any idea?
Thanks in advance!
As mentioned by aaronfc already, there is an open ticket on hibernate JIRA: https://hibernate.atlassian.net/browse/HHH-8804
So the Problem is an collision with Log4j2 converters, more detailed, the db appender JPA converters.
However, the problems occurs with the "fat" jar only...
Workaround: If you use maven-shade-plugin to pack your jar - and don't need any log4j2 db appender, you could exclude the colliding Converter classes:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<filters>
<filter>
<artifact>org.apache.logging.log4j:*</artifact>
<excludes>
<exclude>org/apache/logging/log4j/core/appender/db/jpa/converter/*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
I stumbled upon this also. There is an open ticket on https://hibernate.atlassian.net/browse/HHH-8804
I "workarounded" it by downgrading to Hibernate 4.2.12.Final and JPA2.0. Hope it helps!
Edit:
Sorry, didn't see that this was a two months old post, anyway hope it is useful for somebody :P
In extension to #hartmut's answer, if you're using Gradle, include Gradle Shadow, and do the following in build.gradle:
shadowJar {
exclude 'org/apache/logging/log4j/core/appender/db/jpa/converter/*'
}
You can then run gradle shadowJar to create the jar
I have found a workaround that works. Instead to create a "fat" jar, I have created a Jar with my project and all the dependencies in a separate "lib" folder (included Hibernate of course).
I don't know way, but it works now.

Categories