PlayFramework accessing secondary database data with jpa/hibernate - database

I am trying to connect second db to my webapplication written in PlayFramework2.
I've configured correctly my app. I've added already second source callec crm.
Here is my console log:
--- (RELOAD) ---
[info] play - datasource [jdbc:mysql://localhost/svp] bound to JNDI as DefaultDS
[info] play - datasource [jdbc:mysql://192.168.0.4/scrm_customer] bound to JNDI as CRM
[info] play - database [default] connected at jdbc:mysql://localhost/svp
[info] play - database [CRM] connected at jdbc:mysql://192.168.0.4/scrm_customer
[info] play - Application started (Dev)
I've added to my persistence.xml following:
<persistence-unit name="CRM" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>CRM</non-jta-data-source>
</persistence-unit>
and my configuration for that:
db.default.jndiName=DefaultDS
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/svp"
db.default.user=root
db.CRM.jndiName=CRM
db.CRM.driver=com.mysql.jdbc.Driver
db.CRM.url="jdbc:mysql://192.168.0.4/scrm_customer"
db.CRM.user=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnit
But when I am trying to get some data from second db using code as follow:
List<Customer> allCustomers = (List<Customer>) JPA.em("CRM")
.createQuery("FROM Customer", Customer.class)
.getResultList();
I am getting an error:
[error] play - Cannot invoke the action, eventually got an error: java.lang.RuntimeException: No JPA EntityManagerFactory configured for name [CRM]
[error] application -
! #6kd0136e7 - Internal server error, for (GET) [/SupraADMIN/klienci] ->
play.api.Application$$anon$1: Execution exception[[RuntimeException: No JPA EntityManagerFactory configured for name [CRM]]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10-2.2.4.jar:2.2.4]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10-2.2.4.jar:2.2.4]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]
Caused by: java.lang.RuntimeException: No JPA EntityManagerFactory configured for name [CRM]
at play.db.jpa.JPA.em(JPA.java:34) ~[play-java-jpa_2.10-2.2.4.jar:2.2.4]
at models.Customer.getCRMList(Customer.java:124) ~[na:na]
at controllers.admin.CMS.Customers(CMS.java:157) ~[na:na]
at admin.Routes$$anonfun$routes$1$$anonfun$applyOrElse$24$$anonfun$apply$24.apply(routes_routing.scala:429) ~[na:na]
at admin.Routes$$anonfun$routes$1$$anonfun$applyOrElse$24$$anonfun$apply$24.apply(routes_routing.scala:429) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183) ~[play_2.10-2.2.4.jar:2.2.4]
[error] application - REGUEST: GET /SupraADMIN/klienci GENERATED ERROR: #6kd0136e7: Execution exception in /home/korbeldaniel/Aplikacje/Eclipse/SVP/modules/common/app/models/Customer.java:124
What do I miss? I've checked official documentation, but nothing usefull found.
Please help

Annotate your controller method with following annotation:
#Transactional(value = "CRM", readOnly = true)
and within controller method perform:
JPA.em().createQuery("FROM Customer", Customer.class).getResultList();
Or if you dont want to use annotation:
List<Customer> customers = JPA.withTransaction("CRM", true, new Function0<List<Customer>>() {
#Override
public List<Customer> apply() throws Throwable {
return JPA.em().createQuery("FROM Customer", Customer.class).getResultList();
}
});
I would strongly recommend using JPA.withTransactionAsync instead.

Related

R2DBC-MSSQL how to connect to a database

I am trying to connect to my local SQL Server with R2DBC, unfortunately, I do not know where I am going wrong, I have a lot of experience with R2DBC, I use it all the time with other databases but this is my first time with MSSQL, below is my MSSQL ConnectionFactorythat is failing:
#Bean
override fun connectionFactory(): ConnectionFactory {
val options = builder()
.option(DRIVER, "sqlserver")
.option(HOST, properties.host)
.option(PORT, properties.port.toInt())
.option(USER, properties.username)
.option(PASSWORD, properties.password)
.option(DATABASE, properties.database)
.option(SSL, false)
.build()
val connectionFactory = ConnectionFactories.get(options)
val configuration = ConnectionPoolConfiguration.builder(connectionFactory)
.maxIdleTime(Duration.ofMillis(1000))
.maxSize(20)
.build()
connectionPool = ConnectionPool(configuration)
return ProxyConnectionFactory.builder(connectionPool)
.build()
}
My properties
com:
#Application database
database:
host: PC_NAME\SQLEXPRESS
port: 51306
database: app_database
username: user
password: pass
When I run my application I get the error below:
09:02:40.151 [reactor-tcp-nio-1] DEBUG reactor.pool.SimpleDequePool - failed to warm up extra resource 9/9: java.net.UnknownHostException: Failed to resolve 'PC_NAME\SQLEXPRESS' after 4 queries
09:02:40.153 [parallel-2] ERROR reactor.core.publisher.Operators - Operator called default onErrorDropped
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.transaction.CannotCreateTransactionException: Could not open R2DBC Connection for transaction; nested exception is java.net.UnknownHostException: Failed to resolve 'PC_NAME\SQLEXPRESS' after 4 queries
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open R2DBC Connection for transaction; nested exception is java.net.UnknownHostException: Failed to resolve 'PC_NAME\SQLEXPRESS' after 4 queries
I do not understand where I am going wrong, I can confirm that I have enabled TCP and shown below
And enabled remote connection on my server instance
Does anyone know how this works?

Camel route with Spring Batch: No JobLauncher

I'm deploying a Spring Batch job triggered by a Camel route. Here is the Spring Batch config:
#Configuration
#EnableBatchProcessing
public class JobConfig
{
...
#Bean(name = "personJob")
public Job personJob(JobCompletionNotificationListener personListener, Step personStep)
{
return jobBuilderFactory
.get(...)
.incrementer(new RunIdIncrementer())
.listener(...)
.flow(...)
.end()
.build();
}
...
The Camel route looks like this:
#ApplicationScoped
public class MyRouteBuilder extends RouteBuilder
{
#Override
public void configure() throws Exception
{
from("file://...")
...
.to("spring-batch:personJob?jobLauncherRef=jobLauncher");
}
Running the route above raises the following exception:
[ERROR] Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: spring-batch://personJob?jobLauncherRef=jobLauncher due to: No JobLauncher named jobLauncher found in the registry.
[ERROR] Caused by: java.lang.IllegalStateException: No JobLauncher named jobLauncher found in the registry."}}}}
However, the documentation clearly states:
The #EnableBatchProcessing works similarly to the other #Enable*
annotations in the Spring family. In this case, #EnableBatchProcessing
provides a base configuration for building batch jobs. Within this
base configuration, an instance of StepScope is created in addition to
a number of beans made available to be autowired:
JobRepository: bean name "jobRepository"
JobLauncher: bean name "jobLauncher"
...
So, there should be a bean named "jobLauncher" of the type JobLauncher. Why isn't it found in the registry ?
Many thanks in advance,
Seymour

how to extract data from ElementCollection

I am trying to extract data from an ElementCollection that is contained in StandartFont.
public class DBFonts {
#Id
#GeneratedValue(strategy= GenerationType.AUTO)
private long id;
private String nameFont;
#ElementCollection
#CollectionTable(
name="StandartFont",
joinColumns=#JoinColumn(name="Fonts_id")
#Lob #Basic(fetch = FetchType.LAZY)
#Column(length=100000)
private List<byte[]> StandartFonts; }
Repository:
public interface FontRepo extends JpaRepository<DBFonts,Long> {
List<byte[]> findByStandartFonts(Long fonsId);
}
HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: alter table font add constraint FKpcplr5ixrmh5lbjx0e6peoqo4 foreign key (user_id) references usr (id)
Hibernate: alter table standart_font add constraint FKq7nxy6see56tp2y997fwmsewq foreign key (fonts_id) references font (id)
2018-12-06 16:15:54.338 INFO 6168 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-12-06 16:15:54.884 WARN 6168 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFont': Unsatisfied dependency expressed through field 'fontRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
2018-12-06 16:15:54.884 INFO 6168 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-12-06 16:15:54.886 INFO 6168 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-12-06 16:15:54.896 INFO 6168 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2018-12-06 16:15:54.898 INFO 6168 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-12-06 16:15:54.916 INFO 6168 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-06 16:15:54.928 ERROR 6168 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFont': Unsatisfied dependency expressed through field 'fontRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
It does not work, how to extract data correctly?
Will it work?:
select standart_fonts FROM standart_font where fonts_id=?
How to write this in #Query
Spring cant find attribute with name standartFonts in your class DBFonts and that's why it can't create been with your repository
Unable to locate Attribute with the the given name [standartFonts] on
this ManagedType [spring_mvc.entity.DBFonts]
Spring using reflection get method name (findByStandartFonts) from your repository and parse it: findBy its means select and StandartFonts spring parse as standartFonts and it try to find this field in your #Entity
PS. In id field, please, use Long instead of long. It's good practice.
And use camelCase in your java code...

Grails app connecting to sql server

I have a problem connecting Grails application with Sql server using windows authentication.
This is my connection code:
dataSource_lookup{
pooled = true
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
dialect = "org.hibernate.dialect.SQLServer2008Dialect"
//domain = "webshop"
username = "username"
password = "password"
url = "jdbc:jtds:sqlserver://111.222.3.4:1433/sqlDB;integratedSecurity=true;"
logSql = true
properties {
//integratedSecurity = "true"
maxActive = 50
maxIdle = 20
minIdle = 10
initialSize = 1
minEvictableIdleTimeMillis = 60000
timeBetweenEvictionRunsMillis = 60000
maxWait = 10000
testOnBorrow=true
testOnReturn=true
testWhileIdle=true
validationQuery="SELECT 1"
}
}
I tried connecting to SQL with HeidiSQL and it works. Checkbox for windows authentication must be checked, otherwise connection fails.
In Grails app I receive this message:
Message: Error creating bean with name 'controllerHandlerMappings': Cannot resolve reference to bean 'openSessionInViewInterceptor_lookup' while setting bean property 'interceptors' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openSessionInViewInterceptor_lookup': Cannot resolve reference to bean 'sessionFactory_lookup' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_lookup': Cannot resolve reference to bean 'lobHandlerDetector_lookup' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector_lookup': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Login failed for user 'username'.)
Could someone give me an advice what to do?
Thanks in advance.
In the meantime I tried other things and one of them worked.
This is the solution.
url ="jdbc:jtds:sqlserver://111.222.3.4:1433;databaseName=sqlDB;domain=webshop;useNTLMv2=true;"
Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC
The accepted answer saved me.

Spring Boot postgresql embedded tomcat fails to start

I've set up a Spring Boot starter application. Now switching from embedded db to postgreSQL using properties example from docs and guessing on the dependencies. With setup below, embedded tomcat server fails to launch.
Grateful for any advice.
gradle build
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
//apply plugin: 'jetty'
//apply plugin: 'war'
jar {
baseName = 'base-app'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
}
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.thymeleaf:thymeleaf-spring4")
testCompile("junit:junit")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.postgresql:postgresql:9.2-1004-jdbc4")
compile("org.hibernate:hibernate-validator")
compile('org.hibernate:hibernate-entitymanager:4.0.1.Final')
compile("org.springframework:spring-tx")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
application.properties
spring.thymeleaf.cache=false
server.port=9500
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=testdb
spring.datasource.password=testdb
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=create-drop
error log
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [org/springframework/security/core/userdetails/jdbc/users.ddl]: create table users(username varchar_ignorecase(50) not null primary key,password varchar_ignorecase(500) not null,enabled boolean not null); nested exception is org.postgresql.util.PSQLException: ERROR: type "varchar_ignorecase" does not exist
Position: 29
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getOrderedBeansOfType(EmbeddedWebApplicationContext.java:367)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:268)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:213)
at org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener.lifecycleEvent(ServletContextInitializerLifecycleListener.java:54)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 common frames omitted
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [org/springframework/security/core/userdetails/jdbc/users.ddl]: create table users(username varchar_ignorecase(50) not null primary key,password varchar_ignorecase(500) not null,enabled boolean not null); nested exception is org.postgresql.util.PSQLException: ERROR: type "varchar_ignorecase" does not exist
Position: 29
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 22 common frames omitted
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [org/springframework/security/core/userdetails/jdbc/users.ddl]: create table users(username varchar_ignorecase(50) not null primary key,password varchar_ignorecase(500) not null,enabled boolean not null); nested exception is org.postgresql.util.PSQLException: ERROR: type "varchar_ignorecase" does not exist
Position: 29
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:458)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:206)
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:49)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.execute(DataSourceInitializer.java:108)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:93)
at org.springframework.security.config.annotation.authentication.configurers.provisioning.JdbcUserDetailsManagerConfigurer.initUserDetailsService(JdbcUserDetailsManagerConfigurer.java:160)
at org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsServiceConfigurer.configure(UserDetailsServiceConfigurer.java:48)
at org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsServiceConfigurer.configure(UserDetailsServiceConfigurer.java:33)
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.configure(AbstractConfiguredSecurityBuilder.java:378)
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:327)
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:39)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.authenticationManager(WebSecurityConfigurerAdapter.java:231)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:171)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:276)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:61)
at com.qbmetrics.baseapp.config.WebSecurityConfig$$EnhancerBySpringCGLIB$$4b30fbc7.init(<generated>)
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:369)
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:322)
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:39)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:92)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e1d58644.CGLIB$springSecurityFilterChain$4(<generated>)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e1d58644$$FastClassBySpringCGLIB$$98399566.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e1d58644.springSecurityFilterChain(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 23 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: type "varchar_ignorecase" does not exist
Position: 29
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:395)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:443)
... 52 common frames omitted
In the stack it says what the error is: you're using an invalid data type for your Users table:
nested exception is org.postgresql.util.PSQLException: ERROR: type "varchar_ignorecase" does not exist
Happens when you try to run this:
create table users(username varchar_ignorecase(50) not null primary key,password varchar_ignorecase(500) not null,enabled boolean not null);
The list of valid data types is here: http://www.postgresql.org/docs/9.3/static/datatype.html
Based on the error described, this has been solved in the link spring boot security using jdbcauthentication.
Cause :
So when the application starts up, it executes a create schema sql command (because you added "withDefaultSchema" in your security configuration) which contains 'varchar_ignorecase' in the sql command/query but varchar_ignorecase is not recognised by postgresql or even mysql as a datatype as a result, it is failing.
Solution :
Make modification according to the answer on the link.

Resources