Spring boot and drools integration - java

I'm trying to run drools 6.2.0.Final with Spring Boot 1.2.2.RELEASE. I configured drools as the documentation says. My kie-context.xml configuration file is where I keep the drools beans and looks like this:
<?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:kie="http://drools.org/schema/kie-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
<kie:kmodule id="sample_module">
<kie:kbase name="kbase1" packages="composition-rules">
<kie:ksession name="ksession1" type="stateless"/>
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
as i try to compile the application and run with spring-boot i get the following error:
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6ab6cc3b: startup date [Wed Apr 15 13:57:02 CEST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:357)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:877)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:150)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:342)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at skeleton.StorfinoApplication.main(StorfinoApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:745)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Unable to get all ZipFile entries: /home/lukasz/dev/skeleton/application/target/application-1.0-SNAPSHOT.jar!
at org.drools.core.util.IoUtils.indexZipFile(IoUtils.java:133)
at org.drools.compiler.kie.builder.impl.ZipKieModule.<init>(ZipKieModule.java:20)
at org.drools.compiler.kie.builder.impl.ClasspathKieProject.createInternalKieModule(ClasspathKieProject.java:186)
at org.kie.spring.KModuleBeanFactoryPostProcessor.createKieModule(KModuleBeanFactoryPostProcessor.java:189)
at org.kie.spring.KModuleBeanFactoryPostProcessor.addKieModuleToRepo(KModuleBeanFactoryPostProcessor.java:162)
at org.kie.spring.KModuleBeanFactoryPostProcessor.postProcessBeanFactory(KModuleBeanFactoryPostProcessor.java:121)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:177)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at skeleton.StorfinoApplication.main(StorfinoApplication.java:23)
... 6 more
Caused by: java.io.FileNotFoundException: /home/user-name/dev/skeleton/application/target/application-1.0-SNAPSHOT.jar! (No such file or directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:220)
at java.util.zip.ZipFile.<init>(ZipFile.java:150)
at java.util.zip.ZipFile.<init>(ZipFile.java:164)
at org.drools.core.util.IoUtils.indexZipFile(IoUtils.java:124)
... 21 more
The command I used for building the project is:
mvn clean package and i run it as a jar file (java -jar application/target/application-1.0-SNAPSHOT.jar).
A thing that caught my attention is that the file path (the one which is not found) has an exclamation mark at the end (it is not supposed to be here). The other thing that i observed is that when i run the project in IntelijIdea ide it succeeds to build and works properly.
What could be the reason of such error?

I tried the same and ended up building an spring-boot-starter-drools for that, because there was nothing working for me out there. I didnĀ“t use the XML-Configuration, because the latest Spring configuration is all about doing with Java only - i would also recommend that in your case.
Suggestions:
Just use the starter, as decribed in the starter or in the example project
Integrating Drools into your Spring Boot-Project with this working configuration:
#Configuration
public class DroolsAutoConfiguration {
private static final String RULES_PATH = "rules/";
#Bean
public KieFileSystem kieFileSystem() throws IOException {
KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();
for (Resource file : getRuleFiles()) {
kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8"));
}
return kieFileSystem;
}
private Resource[] getRuleFiles() throws IOException {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
}
#Bean
public KieContainer kieContainer() throws IOException {
final KieRepository kieRepository = getKieServices().getRepository();
kieRepository.addKieModule(new KieModule() {
public ReleaseId getReleaseId() {
return kieRepository.getDefaultReleaseId();
}
});
KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());
kieBuilder.buildAll();
return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
}
private KieServices getKieServices() {
return KieServices.Factory.get();
}
#Bean
public KieBase kieBase() throws IOException {
return kieContainer().getKieBase();
}
#Bean
public KieSession kieSession() throws IOException {
return kieContainer().newKieSession();
}
#Bean
public KModuleBeanFactoryPostProcessor kiePostProcessor() {
return new KModuleBeanFactoryPostProcessor();
}
}
There are conflicts of spring-versions, because Spring Boot is based upon Spring 4.x and kie-spring depends on Spring 3.2 - i got the silliest Exceptions, till in the end I excluded all the 3.2-dependecies in my pom.xml:
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>${drools.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>

Related

Cannot load ApplicationContext due to Hibernate selecting a non-existent column from information_schema.sequences

Problem
I get org.postgresql.util.PSQLException: The column name start_with was not found in this ResultSet. when trying to run applicationContext.refresh(); after I load my configuration.
EDIT: I can replicate this error on any Postgres instance by simply creating a sequence. I think this is an error with Hibernate.
This occurs when Hibernate runs the following query:
select * from information_schema.sequences
It expects the column start_with to be present in the ResultSet.
The exception is being raised specifically in SequenceInformationExtractorHSQLDBDatabaseImpl#sequenceStartValueColumn:
package org.hibernate.tool.schema.extract.internal;
/**
* #author Vlad Mihalcea
*/
public class SequenceInformationExtractorHSQLDBDatabaseImpl extends SequenceInformationExtractorLegacyImpl {
/**
* Singleton access
*/
public static final SequenceInformationExtractorHSQLDBDatabaseImpl INSTANCE = new SequenceInformationExtractorHSQLDBDatabaseImpl();
#Override
protected String sequenceStartValueColumn() {
return "start_with";
}
}
What I've Tried
I found a similar problem on SO. They needed to update Postgres, so I downloaded the Docker images for Postgres 13, 11, and 8. I am able to load Spring and persist entities in all of these versions.
I also tried downgrading my org.postgresql version (to 42.2.02) since I think my database might be a bit old. The same error occurred with my main database, but not with my Docker containers.
My database is using a schema. I tried setting the default schema to its schema in the Hibernate config. This didn't do anything.
I also made my Docker containers use a schema like in my main database. Nothing changed.
Running the query (select * from information_schema.sequences) that is causing the problem, I can see that my Docker containers return identical results to what my database returns.
I compared the calls stacks between running against Docker and my database. The code that is causing the exception is not even run when I'm running against Docker.
Questions
Why is SequenceInformationExtractorHSQLDBDatabaseImpl#sequenceStartValueColumn even being called? As I mentioned, this is not called when I run against my Docker containers.
Why is it searching for a non-existent column?
Is there something wrong with my configuration?
I'm not really sure where else to look on this one.
Details
PostgreSQL version:
PostgreSQL 11.10 (Ubuntu 11.10-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit
POM:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.5.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.5.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.3.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.9</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.23</version>
</dependency>
Configuration:
package main.java.configuration;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.PersistenceContext;
import javax.sql.DataSource;
import java.util.Properties;
#Configuration
#EnableTransactionManagement
public class HibernateConfiguration {
#Bean
public DataSource dataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://myhost:5432/db");
dataSource.setUsername("username");
dataSource.setPassword("pass");
return dataSource;
}
#Bean
#PersistenceContext
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(dataSource());
localContainerEntityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
localContainerEntityManagerFactoryBean.setJpaProperties(hibernateProperties());
localContainerEntityManagerFactoryBean.setPackagesToScan("main.java.dbentities");
localContainerEntityManagerFactoryBean.setPersistenceUnitName("project");
return localContainerEntityManagerFactoryBean;
}
#Bean
public JpaTransactionManager transactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setDataSource(dataSource());
return transactionManager;
}
private static Properties hibernateProperties() {
final Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
hibernateProperties.put("hibernate.show_sql", true);
hibernateProperties.put("hibernate.format_sql", true);
hibernateProperties.put("hibernate.hbm2ddl.auto", "validate");
hibernateProperties.put("hibernate.default_schema", "myschema");
return hibernateProperties;
}
}
Application code:
class HibernateUtil {
public static void main(String[] args) {
final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(HibernateConfiguration.class);
applicationContext.refresh();
applicationContext.close();
}
}
Full stack trace:
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
ERROR SqlExceptionHelper The column name start_with was not found in this ResultSet.
ERROR LocalContainerEntityManagerFactoryBean Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: ifiweekly] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Unable to build DatabaseInformation
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in main.java.configuration.HibernateConfiguration: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: ifiweekly] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Unable to build DatabaseInformation
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at main.java.HibernateUtil.main(Main.java:254)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: ifiweekly] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Unable to build DatabaseInformation
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
... 10 more
Caused by: org.hibernate.exception.SQLGrammarException: Unable to build DatabaseInformation
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:37)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.tool.schema.internal.Helper.buildDatabaseInformation(Helper.java:189)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:61)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:200)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:81)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:327)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1410)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
... 14 more
Caused by: org.postgresql.util.PSQLException: The column name start_with was not found in this ResultSet.
at org.postgresql.jdbc.PgResultSet.findColumn(PgResultSet.java:2589)
at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2485)
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.resultSetStartValueSize(SequenceInformationExtractorLegacyImpl.java:129)
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:59)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.initializeSequences(DatabaseInformationImpl.java:65)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.<init>(DatabaseInformationImpl.java:59)
at org.hibernate.tool.schema.internal.Helper.buildDatabaseInformation(Helper.java:181)
... 23 more
By default, Hibernate tries to choose a dialect that fits to the database version in use. I still couldn't figure out from your text which database version does not work for you. Once you write that with PostgreSQL 13, 11 and 8 you were unable to reproduce this and in the next section you write that this problem occurs with 11.
This might be a bug in one of the older PostgreSQL dialects of Hibernate, so if you could clearly write which version produces this error and which dialect is in use (should be reported on startup), you could create an issue in the issue tracker(https://hibernate.atlassian.net) with the exception details and maybe some more information like the actual columns of the table in the respective PostgreSQL version.

How to configure Selenium WebDriver with Spring Boot for UI testing?

Not able to configure WebDriver correctly hence my functional test are failing for UI.
I looked into both these SO links but not sure how to use the geckodriver.exe here and what is purpose of it.
Spring Boot GUI Testing Selenium WebDriver
Spring Boot Web Application using Selenium WebDriver
I also looked for some online tutorials where Selenium is configured with Spring Boot but most of them are with older versions of Spring.
UPDATE:
Downloaded and stored IEDriverServer.exe in C:\FAST directory.
Added maven dependency for IE
Modified code base by adding System.getProperty and pointing it to the location of IEDriverServer.exe
Any guidance will be helpful.
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
</dependency>
</dependencies>
src/main/java/Application.java
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Bean
public WebDriver webDriver() {
return new InternetExplorerDriver();
}
}
src/test/java/ApplicationTests.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class ApplicationTests {
#Test
public void contextLoads() {
}
}
GoogleSearchPageSeleniumTests.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class GoogleSearchPageSeleniumTests {
#Autowired
private WebDriver webDriver;
#Before
public void setup() {
System.setProperty("webdriver.ie.driver", "C:\\FAST\\IEDriverServer.exe");
webDriver = new InternetExplorerDriver();
}
#Test
public void getSearchPage() {
this.webDriver.get("https://www.google.com");
WebElement element = this.webDriver.findElement(By.name("q"));
assertNotNull(element);
}
}
Error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.jpmchase.gct.ft.GoogleSearchPageSeleniumTests': Unsatisfied dependency expressed through field 'webDriver'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webDriver' defined in com.jpmchase.gct.ft.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'webDriver' threw exception; nested exception is java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:393)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webDriver' defined in com.jpmchase.gct.ft.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'webDriver' threw exception; nested exception is java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:353)
at org.springframework.boot.test.autoconfigure.web.servlet.WebDriverScope.get(WebDriverScope.java:58)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:350)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581)
... 28 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'webDriver' threw exception; nested exception is java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
... 40 more
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32)
at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:291)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:213)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:152)
at com.jpmchase.gct.ft.Application.webDriver(Application.java:20)
at com.jpmchase.gct.ft.Application$$EnhancerBySpringCGLIB$$fe85b267.CGLIB$webDriver$0(<generated>)
at com.jpmchase.gct.ft.Application$$EnhancerBySpringCGLIB$$fe85b267$$FastClassBySpringCGLIB$$88167d66.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
at com.jpmchase.gct.ft.Application$$EnhancerBySpringCGLIB$$fe85b267.webDriver(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 41 more
2019-02-08 14:38:56.650 INFO 12096 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#3c77d488: startup date [Fri Feb 08 14:38:56 EST 2019]; root of context hierarchy
Process finished with exit code -1
Finally this is what I tried and it worked.
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.3</version>
<scope>test</scope>
</dependency>-->
</dependencies>
src/test/resources (manual download of exe required)
chromedriver.exe
BaseSeleniumTests.java
public abstract class BaseSeleniumTests {
private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
protected WebDriver driver;
#Before
public void setUp() {
String driverFile = findFile();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(driverFile))
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
options.addArguments("--headless");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.merge(capabilities);
this.driver = new ChromeDriver(service, options);
}
private String findFile() {
ClassLoader classLoader = getClass().getClassLoader();
URL url = classLoader.getResource(CHROMEDRIVER_EXE);
return url.getFile();
}
#After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
GoogleSearchPageTraditionalSeleniumTests.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {
#Test
public void getSearchPage() {
this.driver.get("https://www.google.com");
WebElement element = this.driver.findElement(By.name("q"));
assertNotNull(element);
}
}
Please see my answer here Use Webdriver Manager on how to invoke browser without the need to download the binary files (You will need to add a dependecy to your maven) then the rest is simple , so your code will looks like this:
#Test
public void getSearchPage() {
WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();
driver.webDriver.get("https://www.google.com");
WebElement element = driver.webDriver.findElement(By.name("q"));
assertNotNull(element);
}
You will need to
add a Maven dependency to the selenium-ie-driver
Download the Internet Explorer Webdriver
Set the system property webdriver.ie.driver to the path of the executable
Selenium starts this as a background process and communicates via network connection. The webdriver takes control of the Internet Explorer.

errors starting a simple spring boot application

Im trying to run a simple spring boot application, i have filled the application.properties with appropriate parameters to creat a datasource based on jpa and mysql configuration, and i have specified in the pom.xml some of the dependencies that my application may require in order to run, but i still get the same error when i start my application, here is my configuration files, i hope i can get some help here !
i want the application to create in my database the table using orm techonolgy for the begining but im stuck with these errors !!
pom.xml file
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>objectExchange</groupId>
<artifactId>exchange</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>objectExchange</name>
<description>ObjectExchange Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
the application.properties file
spring.datasource.url = jdbc:mysql://localhost:3306/db_objexchange
spring.datasource.username = root
spring.datasource.password =
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.jpa.database = MYSQL
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
the application file :
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ObjectExchangeApplication {
public static void main(String[] args) {
SpringApplication.run(ObjectExchangeApplication.class, args);
}
}
the class for persistance with jpa
package com.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class utilisateur implements Serializable {
#Id
#GeneratedValue
private Long id;
private String nom;
private String prenom;
public utilisateur() {
super();
}
public utilisateur(Long id, String nom, String prenom) {
super();
this.id = id;
this.nom = nom;
this.prenom = prenom;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
this are the file i have on my application and i keep getting these errors :
:: Spring Boot :: (v1.4.1.RELEASE)
2016-09-25 19:59:02.908 INFO 4952 --- [ main] com.ObjectExchangeApplication : Starting ObjectExchangeApplication on user-PC with PID 4952 (C:\Users\user\workspace\objectExchange\target\classes started by user in C:\Users\user\workspace\objectExchange)
2016-09-25 19:59:02.918 INFO 4952 --- [ main] com.ObjectExchangeApplication : No active profile set, falling back to default profiles: default
2016-09-25 19:59:03.277 INFO 4952 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1eb5ee5: startup date [Sun Sep 25 19:59:03 WEST 2016]; root of context hierarchy
2016-09-25 19:59:05.193 WARN 4952 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/com/mysql/fabric/FabricCommunicationException.class]; nested exception is java.util.zip.ZipException: invalid LOC header (bad signature)
2016-09-25 19:59:05.284 ERROR 4952 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/com/mysql/fabric/FabricCommunicationException.class]; nested exception is java.util.zip.ZipException: invalid LOC header (bad signature)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:303) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:248) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:137) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:237) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:204) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:324) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:246) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at com.ObjectExchangeApplication.main(ObjectExchangeApplication.java:10) [classes/:na]
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method) ~[na:1.8.0_92]
at java.util.zip.ZipFile.access$1400(Unknown Source) ~[na:1.8.0_92]
at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source) ~[na:1.8.0_92]
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(Unknown Source) ~[na:1.8.0_92]
at java.util.zip.InflaterInputStream.read(Unknown Source) ~[na:1.8.0_92]
at java.io.FilterInputStream.read(Unknown Source) ~[na:1.8.0_92]
at java.io.BufferedInputStream.fill(Unknown Source) ~[na:1.8.0_92]
at java.io.BufferedInputStream.read1(Unknown Source) ~[na:1.8.0_92]
at java.io.BufferedInputStream.read(Unknown Source) ~[na:1.8.0_92]
at org.springframework.asm.ClassReader.readClass(ClassReader.java:463) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.asm.ClassReader.<init>(ClassReader.java:426) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:53) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:279) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
... 19 common frames omitted
I really hope i can get some help as soon as possible, and thank you all so much !!
Your error is this:
Failed to read candidate component class: URL
[jar:file:/C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/com/mysql/fabric/FabricCommunicationException.class];
nested exception is java.util.zip.ZipException: invalid LOC header
(bad signature)
This suggests that mysql-connector-java-5.1.39.jar is corrupt.
Solution
Remove C:/Users/user/.m2/repository (or at the very least C:/Users/user/.m2/repository/mysql/mysql-connector-java/).
This will force maven to redownload mysql-connector-java's jar when you rebuild (ie: mvn clean install).
Include the dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
instead of
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
in your POM.xml
Another issue could be the mysql jar located in your .m2 folder. Try to delete the jar file, update your pom.xml and try again.
Working on project I stumble upon the not exact, but rather similar error.
Caused by: org.apache.ignite.IgniteCheckedException: Failed to find configuration in: org.springframework.boot.loader.jar.ZipInflaterInputStream#...
In my case the real reason for such error was removing one parameter inside SpringBoot configuration XML file. I don't see real reason for error but fact is....
Correct config runs without errors is below:
<beans profile="local,default">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
The incorrect configuration causing the same error was removed 'default' param:
<beans profile="local">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
The last configuration was caused the same error on SpringBott app start-up.
The configuration parameters in my case are related to Apache Ignite. Cleaning up /.m2/ and Gradle cache folders didn't help.
As one more solution can be running application with specifying explicit Spring profile like:
java -jar -Dspring.profiles.active=local xxx_YOUR_FAT_JAR-FILE.jar

Spring Boot and Thymeleaf 3.0.0.RELEASE integration

I have a problem, when I try integrate Spring Boot 1.3.5.RELEASE and Thymeleaf 3.0.0.Release. I know that Spring Boot now support Thymeleaf 3 version so I try workaround this problem like this :
#SpringBootApplication(exclude={org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.class})
and add my own SpringWebConfig configuration.
unfortunately received error like this :
java.lang.ClassNotFoundException: org.thymeleaf.resourceresolver.IResourceResolver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_66]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_66]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_66]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_66]
... 37 common frames omitted
Wrapped by: java.lang.NoClassDefFoundError: org/thymeleaf/resourceresolver/IResourceResolver
wrapped by: java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration due to org/thymeleaf/resourceresolver/IResourceResolver not found. M ake sure your own configuration does not rely on that class. This can also happen if you are #ComponentScanning a springframework package (e.g. if you put a #ComponentScan in the default package by mistake)
It's much simpler, just read this:
http://docs.spring.io/spring-boot/docs/1.5.x/reference/htmlsingle/#howto-use-thymeleaf-3
<properties>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
spring boot 1.4.0 + thymeleaf 3.0.1
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.0.3</version>
</dependency>
As stated in the documentation for 1.4.7.RELEASE:
https://docs.spring.io/spring-boot/docs/1.4.7.RELEASE/reference/htmlsingle/#howto-use-thymeleaf-3
If you use Gradle put this in the build.gradle file:
Gradle: build.gradle
ext['thymeleaf.version'] = '3.0.2.RELEASE'
ext['thymeleaf-layout-dialect.version'] = '2.1.1'
If you use Maven put this in the pom.xml file:
Maven: pom.xml
<properties>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
(since I have not enough reputation, I posted an answer instead of a comment on one of the previous answers. Especially the build.gradle part.)
For Maven project just add following line on pom.xml
<properties>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
For gradle project create a gradle.properties file with following contents
thymeleaf.version=3.0.2.RELEASE
thymeleaf-layout-dialect.version=2.1.1
I have Spring Boot 1.3.3 working with Thymeleaf 3 using this Configuration class. I recall having to work to get around that same exception. Also, ThymeleafAutoConfiguration is excluded in my autoscan setup, like it is in yours.
#Configuration
#EnableConfigurationProperties(ThymeleafProperties.class)
#ConditionalOnClass(SpringTemplateEngine.class)
#AutoConfigureAfter(WebMvcAutoConfiguration.class)
public class ThymeleafConfiguration extends WebMvcConfigurerAdapter implements ApplicationContextAware {
private ApplicationContext applicationContext;
#Autowired
ThymeleafProperties properties;
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
#Bean
public ViewResolver viewResolver() {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
resolver.setCharacterEncoding("UTF-8");
return resolver;
}
private TemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.addTemplateResolver(urlTemplateResolver());
engine.addTemplateResolver(templateResolver());
// pre-initialize the template engine by getting the configuration. It's a side-effect.
engine.getConfiguration();
return engine;
}
private ITemplateResolver templateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setPrefix("classpath:templates/");
resolver.setSuffix(".html");
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(properties.isCache());
return resolver;
}
private UrlTemplateResolver urlTemplateResolver() {
return new UrlTemplateResolver();
}
}
(The resolver.setPrefix, resolver.setSuffix, and resolver.setTemplateMode may not be necessary anymore, but they were with the first beta release.)
Do the simply step by step
1. adding dependency for thymeleaf.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2. adding dependency for thymeleaf dialect.
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
3. SpringBoot autoconfiguration for thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.enabled=true
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.prefix=/WEB-INF/html/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML
spring.thymeleaf.reactive.max-chunk-size=0

How to configure transaction management for spring 4/hibernate 4.3 app deployed to WAS 8

Have found a million posts on this and tried just as many approaches. Fact is I can't find anywhere an example of configuring a Spring app with Hibernate, that has transactions supported OK in Websphere 8(.5).
Here's my spring config:
#Configuration
#ComponentScan(basePackages={"foobar"})
#EnableTransactionManagement // equiv to <tx:annotation-driven/>
#EnableAspectJAutoProxy(proxyTargetClass=true) // equiv to <aop:aspectj-autoproxy/>
public class MySpringConfiguration {
#Autowired
private AutowireCapableBeanFactory beanFactory;
#Bean(name = "dataSource")
public DataSource dataSource() {
try {
final javax.naming.InitialContext ic = new javax.naming.InitialContext();
return (javax.sql.DataSource) ic.lookup(FoobarConfiguration.getInstance().getDatasourceJNDIName());
} catch (final NamingException ne) {
throw new RuntimeException("Failed to access JNDI lookup using (" + FoobarConfiguration.getInstance().getDatasourceJNDIName() + ")", ne);
}
}
#Bean(name = "sessionFactory")
public SessionFactory sessionFactory() {
LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(dataSource());
builder.scanPackages("foobar.om");
// builder.setJtaTransactionManager(new WebSphereUowTransactionManager());
// Didn't work. gave: org.hibernate.TransactionException: Could not register synchronization for container transaction
Properties props = buildHibernateProperties();
builder.addProperties(props);
return builder.buildSessionFactory();
}
/**
* These were taken, with comments, from application-config conversion
*/
private Properties buildHibernateProperties() {
Properties props = new Properties();
// Set the default-schema for Hibernate to use.
props.setProperty("hibernate.default_schema", "foobar");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.DB2Dialect");
props.setProperty("hibernate.hbm2ddl.auto", "validate");
// Sets the DEBUG Level of the hibernate: SQL generation layer.
props.setProperty("hibernate.show_sql", "true");
props.setProperty("hibernate.generate_statistics", "false");
props.setProperty("hibernate.order_updates", "true");
props.setProperty("hibernate.order_inserts", "true");
// Not needed as we have Spring: http://stackoverflow.com/questions/4293098/how-to-integrate-spring-with-hibernate-session-and-transaction-management
// props.setProperty("hibernate.current_session_context_class", "org.hibernate.context.internal.ThreadLocalSessionContext");
props.setProperty("hibernate.cache.use_query_cache", "false");
props.setProperty("hibernate.cache.use_second_level_cache", "false");
return props;
}
#Bean(name = "transactionManager")
public HibernateTransactionManager transactionManager() {
return new HibernateTransactionManager(sessionFactory());
}
#Bean(name = "persistenceExceptionTranslationPostProcessor")
public PersistenceExceptionTranslationPostProcessor getExceptionProcessor() {
return new PersistenceExceptionTranslationPostProcessor();
}
}
The version as shown works fine in local Jetty environment. It's on deployment to Websphere that an exception is thrown when commence a transaction:
org.hibernate.HibernateException: No CurrentSessionContext configured!
You can see in the config 2 earlier commented-out approaches. The former, setJtaTransactionManager is from the class-level javadoc note on http://docs.spring.io/spring/docs/4.0.2.RELEASE/javadoc-api/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.html.
But if I should have something in there then I don't know what it is.
mvn deps:
<spring-version>4.0.5.RELEASE</spring-version>
<hibernate-version>4.3.5.Final</hibernate-version>
...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
<exclusions>
<!-- The following has classes (e.g. SystemException) that clashes with
an equivalent in Jetty -->
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
EDIT 21/07: Stacktrace as requested by James:
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public foobar.pages.MaintainOpPage(org.apache.wicket.request.mapper.parameter.PageParameters)' and argument ''. An exception has been thrown during construction!
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:194)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:76)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:100)
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:221)
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:862)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3748)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:283)
at com.ibm.ws.ssl.channel.impl.SSLConnectionLink.determineNextChannel(SSLConnectionLink.java:1048)
at com.ibm.ws.ssl.channel.impl.SSLConnectionLink.readyInboundPostHandshake(SSLConnectionLink.java:716)
at com.ibm.ws.ssl.channel.impl.SSLConnectionLink$MyHandshakeCompletedCallback.complete(SSLConnectionLink.java:412)
at com.ibm.ws.ssl.channel.impl.SSLUtils.handleHandshake(SSLUtils.java:1066)
at com.ibm.ws.ssl.channel.impl.SSLHandshakeIOCallback.complete(SSLHandshakeIOCallback.java:87)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1814)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)
at java.lang.reflect.Constructor.newInstance(Constructor.java:539)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:171)
... 45 more
Caused by: org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1012)
at foobar.repository.impl.OpDao.findOp(OpDao.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at $Proxy59.findOp(Unknown Source)
at foobar.service.impl.OpService.generateNewTrn(OpService.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at $Proxy62.generateNewTrn(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:435)
at $Proxy69.generateNewTrn(Unknown Source)
at foobar.pages.MaintainOpPage.<init>(MaintainOpPage.java:59)
... 50 more
I only had issues when I upgraded from 4.1.0 to 4.3.5. Unless you need 4.3.5 functionality you don't need to downgrade all the way to 3. The 4.3.5 version does work fine in Jetty though. It is only websphere I have issues with. Imagine that.

Categories

Resources