In a Spring MVC server I have this warning every time I use docx4j to generate a docx. The server functions well, but I have a huge log with this warning
2022-04-27 18:00:46.241 [http-nio-8080-exec-3] WARN org.docx4j.XmlUtils - default SAXParserFactory property : null
Please consider using Xerces.
2022-04-27 18:00:46.248 [http-nio-8080-exec-3] WARN org.docx4j.XmlUtils - default DocumentBuilderFactory property: null
Please consider using Xerces.
My pom.xml is:
<!-- Doc4j -->
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
<version>8.3.4</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-core</artifactId>
<version>8.3.4</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>8.3.4</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
</dependency>
What am I missing?
If you get ...
[main] WARN org.docx4j.XmlUtils - default SAXParserFactory property : null
Please consider using Xerces.
[main] WARN org.docx4j.XmlUtils - default DocumentBuilderFactory property: null
Please consider using Xerces.
... you need xerces on the CP and you need to set the property in docx4j.properties for sax parser to xerces
From docx4j.properties [JAXP factories] section uncomment ... [javax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl]
*** NOTE you will have a different package name for SaxParserFactoryImpl based on the version of xerces
The version of docx4j will have the dependencies needed to be on the CP in /dependencies
if you get ...
[main] WARN org.docx4j.utils.ResourceUtils - Couldn't get resource: docx4j.properties
[main] WARN org.docx4j.Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
... you have not deployed docx4j.properties - docx4j has defaults, so you first need to deploy docx4j.properties before you can affect those defaults
you need to create (or copy from source ~/resources/) [docx4j.properties]
org.docx4j.Docx4jProperties.java loads docx4j.properties on init() to overwrite the defaults
Related
I am trying to replace my local geckodriver.exe with WebDriverManager, but when i invoke
WebDriverManager.firefoxdriver().setup();
i get the following error
4391 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4704 [main] WARN io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present) ... trying again using latest driver stored in cache
4704 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4876 [main] ERROR io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present)
java.lang.TypeNotPresentException: Type com.google.gson.internal.LinkedTreeMap not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
...
at io.github.bonigarcia.wdm.WebDriverManager.fallback(WebDriverManager.java:825)
at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:802)
at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:599)
at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:287)
I am using the latest 5.0.3 WebDriverManager from maven
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
TypeNotPresentException is thrown when an application tries to access a type using a string representing the type's name, but no definition for the type with the specified name can be found.
It's pretty similar to ClassNotFoundException, but not checked during compilation.
But the root cause is:
com.google.gson.internal.LinkedTreeMap not present in the project classpath.
Try to add gson dependency to the project.
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
https://docs.oracle.com/javase/9/docs/api/java/lang/TypeNotPresentException.html
Change the WebDriverManager scope to test in pom.xml as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>
or change the scope to compile in pom.xml as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>compile</scope>
</dependency>
Additionally, you may need to add the slf4j dependency as follows:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
As per Driver Management - Feature:
Although not mandatory, it is highly recommended to use a logger library to trace your application and tests. In the case of WebDriverManager, you will see the relevant steps of the driver management following its traces. See for example the following tutorial to use SLF4J and Logback. Also, you can see an example of a WebDriverManager test using logging here (this example uses this configuration file).
Reference
You can find a couple of relevant detailed discussion in:
I am getting an error while executing the basic website launch using web driver manager
I'd like to work with Redis for manipulating sessions.But I get failure when running the spring boot app.So I guess that this error is coming from maven dependencies especially version conflicts.
I am getting exception after upgrading spring boot version to 2.5.0 from 1.5.9.Release.
Below are maven dependecies:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.5.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
When I run the spring boot app, I get the belowed error:
2021-07-14 16:47:52,711 [localhost-startStop-1] WARN (AbstractApplicationContext.java:591) - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.getConfig(Ljava/lang/String;)Ljava/util/List;
2021-07-14 16:47:52,824 [localhost-startStop-1] INFO (ConditionEvaluationReportLoggingListener.java:136) -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-14 16:47:52,841 [localhost-startStop-1] ERROR (LoggingFailureAnalysisReporter.java:40) -
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.getNotifyOptions(ConfigureNotifyKeyspaceEventsAction.java:74)
The following method did not exist:
org.springframework.data.redis.connection.RedisConnection.getConfig(Ljava/lang/String;)Ljava/util/List;
The method's class, org.springframework.data.redis.connection.RedisConnection, is available from the following locations:
jar:file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-data-redis-2.5.1.jar!/org/springframework/data/redis/connection/RedisConnection.class
The class hierarchy was loaded from the following locations:
org.springframework.data.redis.connection.RedisConnection: file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-data-redis-2.5.1.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.redis.connection.RedisConnection
Any help would be really appericiated, let me know if required more information from my side.
EDIT:
Removed version for dependencies from pox.xml
so updated dependencies looks like below:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
I am getting below error message:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-14 18:41:22,473 [localhost-startStop-1] ERROR (LoggingFailureAnalysisReporter.java:40) -
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
io.gupshup.blockedno.BlockNoSession.sessionRepository(BlockNoSession.java:120)
The following method did not exist:
org.springframework.session.data.redis.RedisOperationsSessionRepository.<init>(Lorg/springframework/data/redis/connection/RedisConnectionFactory;)V
The method's class, org.springframework.session.data.redis.RedisOperationsSessionRepository, is available from the following locations:
jar:file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-data-redis-2.5.0.jar!/org/springframework/session/data/redis/RedisOperationsSessionRepository.class
jar:file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-1.3.5.RELEASE.jar!/org/springframework/session/data/redis/RedisOperationsSessionRepository.class
The class hierarchy was loaded from the following locations:
org.springframework.session.data.redis.RedisOperationsSessionRepository: file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-data-redis-2.5.0.jar
org.springframework.session.data.redis.RedisIndexedSessionRepository: file:/home/bhanu/tomcat/tomcat8/webapps/BlockedNo-blockno/WEB-INF/lib/spring-session-data-redis-2.5.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.session.data.redis.RedisOperationsSessionRepository
I created a small second level cache program by using 'hibernate 5.3.1.final' dependency.I used below dependencies to work with Second level cache.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.3.1.Final</version>
</dependency>
In this dependency the 'EhcacheRegionFactory' package name was changed.so we need to use like below property in our 'hibernate.cfg.xml'file.
<property name="hibernate.cache.region.factory_class">
org.hibernate.cache.ehcache.internal.EhcacheRegionFactory
</property>
In hibernate 5.3 the second level cache is working fine but 'query-cache' is not working.i am getting below exception when iam enabling the query-cache in 'hibernate.cfg.xml'.
->Exception in thread "main" java.lang.ExceptionInInitializerError
->Caused by: org.hibernate.service.spi.ServiceException: Unable to create
requested service [org.hibernate.cache.spi.CacheImplementor]
->Caused by: org.hibernate.cache.CacheException: On-the-fly creation of
JCache Cache objects is not supported
[org.hibernate.cache.spi.TimestampsRegion]
How to solve this one?
But The same program when i tried with hibernate 5.2.17 dependency the query cache working fine.
Use Hibernate ORM Hibernate Core ยป 5.3.4.Final dependencies it will work
I have some trouble getting rid of debug messages generated by Spring (similiar to the following ones; there are thousands of those entries):
19:58:08.380 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'propertyPlaceholderConfigurer'
19:58:08.380 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'propertyPlaceholderConfigurer'
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'appConfig'
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'appConfig'
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'appConfig' to allow for resolving potential circular references
19:58:08.384 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'appConfig'
In related questions, there were many suggestions involving log4j, web.xml, ....
However, I am not using any of those - I simply instantiate an AnnotationConfigApplicationContext and start creating beans.
In my pom.xml file, there are no references to any logging framework - I only include the spring dependencies:
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- ... -->
<artifactId>spring-tx</artifactId>
<!-- ... -->
<artifactId>spring-boot-starter</artifactId>
<!-- ... -->
<artifactId>spring-web</artifactId>
<!-- ... -->
I read somewhere that Spring seems to use "Commons logging" by default, which I unsuccessfully tried to disable using (as shown in Turn Off Apache Common Logging ):
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
In addition, I tried to exclude the commons logging in my pom.xml by adding:
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
Still no luck, however.
Next, I tried including a dependency to log4j, hoping this would override the default logging. As the format of the messages stayed the same, it seems that this attempt was also not successfull.
What could I try next?
First: Is slf4j on classpath?
SLF4J is another log abstraction for Java, which also could be used together with Spring framework. Many libraries / products have switched to slf4j.
Are there any dependencies with 'slf4j' in its name? Try mvn dependency:tree -Dverbose=true, and look if slf4j appears. If so, look at slf4j website for more information about its setup.
Second: which log4j config file is used?
Hint to detect if log4j is used, and if a log4j config file is somewhere on the classpath:
Try to set property log4j.debug to 'true'.
When using mvn exec:java, simply add -Dlog4j.debug=true to command line.
If this is a Junit test with the maven surefire plugin, try set systemProperties in Surefire plugin itself: http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html
I have read post related with this but not get any answer working for me.
I am configuring second level cache in Hibernate v4.3. And I have used MySQL 5.0
I have written following elements in hibernate.cfg.xml
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
I have annotated my Entity class for cache as follows
#Entity
#Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Employee { ....}
Following exception is shown when run
INFO: HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2442)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2438)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1855)
at com.example.hibernate.Hibernate4Main.main(Hibernate4Main.java:32)
Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheRegionFactory]
at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:101)
at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:46)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:83)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223)
... 7 more
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.ehcache.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:128)
at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:87)
... 10 more
I have seen than there are different cache providers for Hibernate v3 like EhCacheProvoider. All are in org.hibernate.cache package.
But for Hibernate 4.3 there are only 3 classes as RegionFactory.class and other two are of exception.
1. What is wrong with above code?
2. What are major changes made for Second level cache configuration in Hibernate 4.3?
I solved this for my configuration. Viewing the "effective pom" for my project had shown:
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.7.Final</version>
</dependency>
...
</dependencies>
</dependencyManagement>
along with most of my other dependencies.
Copying that hibernate-ehcache dependency into my actual project pom file added a second entry for it outside of the <dependencyManagement/> tag and that solved my problem. I had thought that because it was already included in the effective pom I didn't need to add it but apparently that is not the case for hibernate-ehcache as it seems to be for other packages.
Your pom.xml file should look like below
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.7.Final</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.7.1</version>
</dependency>
and Your hibernate.cfg.xml should contain the following configuration
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
Refer this - http://architects.dzone.com/articles/hibernate-4-and-ehcache-higher
add hibernate-ehcache jar to your project, that will solve the problem.
I got the same problem before. I added slf4j-api-1.6.1.jar to the project and fixed this problem. I was using Hibernate 4.3.5.