Giter VIP home page Giter VIP logo

grails-boot's Introduction

grails-boot's People

Contributors

codeconsole avatar graemerocher avatar lhotari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grails-boot's Issues

Default spring.gsp.tldScanPattern by classpath

One of the things that is nice about Spring Boot is that it will automatically make reasonable defaults. It would be nice if spring.gsp.tldScanPattern could be defaulted to include Spring's TLD (and possibly other TLD on the classpath).

Error creating bean with name 'jspTagLibraryResolver'

I was looking at getting some of my gsp's ported over to my new Boot application. I was working on the 'gsp-example' app to get some insights on to how to go about it.

I understand that this example was written a while ago. The only change I made was to update the 'spring-boot-starter-parent' version to the latest version - '1.1.6.RELEASE'.

    <dependency>
        <groupId>org.grails</groupId>
        <artifactId>grails-gsp-spring-boot</artifactId>
        <version>1.0.0.RC1</version>
    </dependency>

When starting the app, I'm seeing following exception. Any help would be appreciated. Thanks!


. ____ _ __ _ _
/\ / ' __ _ ()_ __ __ _ \ \ \
( ( )_
| '_ | '| | ' / ` | \ \ \
/ )| |)| | | | | || (| | ) ) ) )
' |
| .**|| ||| |**, | / / / /
=========||==============|/=///_/
:: Spring Boot :: (v1.1.6.RELEASE)

2014-09-19 15:39:53.695 INFO 34049 --- [ main] hello.Application : Starting Application on roadblock.cybersource.com with PID 34049 (/home/wraphale/accurev/Demos/grails-boot-master/sample-apps/gsp/gsp-example/target/classes started by wraphale in /home/wraphale/accurev/Demos/grails-boot-master/sample-apps/gsp/gsp-example)
2014-09-19 15:39:53.706 DEBUG 34049 --- [ main] o.s.boot.SpringApplication : Loading source class hello.Application
2014-09-19 15:39:54.496 INFO 34049 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@473b46c3: startup date [Fri Sep 19 15:39:54 PDT 2014]; root of context hierarchy
2014-09-19 15:39:56.494 WARN 34049 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jspTagLibraryResolver' defined in class path resource [grails/gsp/boot/GspAutoConfiguration$GspJspIntegrationConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.codehaus.groovy.grails.web.pages.ext.jsp.TagLibraryResolverImpl grails.gsp.boot.GspAutoConfiguration$GspJspIntegrationConfiguration.jspTagLibraryResolver()] threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:990)
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:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at hello.Application.main(Application.java:14)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.codehaus.groovy.grails.web.pages.ext.jsp.TagLibraryResolverImpl grails.gsp.boot.GspAutoConfiguration$GspJspIntegrationConfiguration.jspTagLibraryResolver()] threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 21 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext

really hard to initialize second datasource with HibernateGormAutoConfiguration

Hi, I couldn't find the issue tracker for gorm-hibernate4-spring-boot, so please help me find it if this one is GSP-specific.

I wanted to set up a second data source (primary data source against postgres and second datasource against Vertica). We have the same code in a Grails project that works fine.

Here are the issues I have found so far:

  1. HibernateGormAutoConfiguration is hardcoded as:
        initializer = new HibernateDatastoreSpringInitializer(classLoader, packages as String[])
        initializer.resourceLoader = resourceLoader
        initializer.setConfiguration(getDatastoreConfiguration())
        initializer.configureForBeanDefinitionRegistry(registry)

But HibernateDatastoreSpringInitializer is hardcoded as:

    String defaultDataSourceBeanName = "dataSource"
    Set<String> dataSources = [defaultDataSourceBeanName]

So adding a second datasource actually required:
a) subclassing HibernateGormAutoConfiguration with my own auto configuration class that copies/pastes the code except to insert the line:

        //NOTE: change from parent class, add vertica data source
        initializer.dataSources = [ 'dataSource', 'dataSource_vertica' ]

b) add HibernateGormAutoConfiguration to the excludes list of auto configuration, or else both run

  1. HibernateGormAutoConfiguration.EagerInitProcessor has the code:

But the PostInitializingHandling bean is registered once per datasource, we can see this in a for loop over datasources:

                "org.grails.gorm.hibernate.internal.POST_INIT_BEAN-${dataSourceName}$suffix"(PostInitializationHandling) { bean ->
                    grailsApplication = ref(GrailsApplication.APPLICATION_ID)
                    bean.lazyInit = false
                }

So we end up with an exception:

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [grails.orm.bootstrap.HibernateDatastoreSpringInitializer$PostInitializationHandling] is defined: expected single matching bean but found 2: org.grails.gorm.hibernate.internal.POST_INIT_BEAN-dataSource_vertica_dataSource_vertica,org.grails.gorm.hibernate.internal.POST_INIT_BEAN-dataSource
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
    at org.grails.datastore.gorm.boot.autoconfigure.HibernateGormAutoConfiguration$EagerInitProcessor.postProcessBeforeInitialization(HibernateGormAutoConfiguration.groovy:115)
  1. The datasource names are a little wonky. In HibernateDatastoreSpringInitializer there is code like this:
            for(dataSourceName in dataSources) {

                boolean isDefault = dataSourceName == defaultDataSourceBeanName
                String suffix = isDefault ? '' : '_' + dataSourceName
                String prefix = isDefault ? '' : dataSourceName + '_'
                def sessionFactoryName = isDefault ? defaultSessionFactoryBeanName : "sessionFactory$suffix"
                def hibConfig = configurationObject["hibernate$suffix"] ?: configurationObject["hibernate"]

...
                        dataSource = ref(dataSourceName)

For my second data source I desire the ultimate data source's name to be "dataSource_vertica". So that's the name I've put into the HibernateDatastoreSpringInitializer.dataSources field.

But you can see above the suffix has been determined as _dataSource_vertica, so now the session factory has been named "sessionFactory_dataSource_vertica" instead of just "sessionFactory_vertica". And it's looking for hibernate properties "hibernate_dataSource_vertica".

So I think the "suffix" and "prefix" variables should not include dataSourceName.

  1. In my application.yml I have:
  hibernate:
    hbm2ddl.auto: ''
    dialect: mycompany.hibernate.dialect.PostgresSequencePerTableDialect
  hibernate_dataSource_vertica:
    hbm2ddl.auto: ''
    dialect: mycompany.hibernate.dialect.VerticaDialect

But as I showed in #1, HibernateGormAutoConfiguration has:

        initializer.setConfiguration(getDatastoreConfiguration())

where getDatastoreConfiguration() is defined as:

    protected Properties getDatastoreConfiguration() {
        if(environment != null) {
            def config = environment.getSubProperties("hibernate.")
            def properties = new Properties()
            for(entry in config.entrySet()) {
                properties.put("hibernate.${entry.key}".toString(), entry.value)
            }
            return properties
        }
    }

You see the same data store configuration is used for both datasources, whereas I wanted to use a different one for each.

Provide samples with "Groovy" TLDs

Many users trying GSPs with boot will be doing so for the first time. One of GSPs strengths is the extensive TLD definitions. For those that are not new to Grails, integrating with Boot will certainly be new. It would be real cool to see an example of using some of the TLD extensions. A few tags that come to mind are:

  • Fields Plugin <f:all bean="person"/>
  • Paginate <g:paginate controller="book" action="list" total="${bookCount}" />

Please keep in mind that I am not a Grails expert, so these libraries are simply suggestions. The point is to demo some of the coolest GSP libraries out there.

Not knowing the code internals I suppose it is possible some libraries will not work with Boot. I think trying to ensure (or work towards) the entire ecosystem is available will be very valuable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.