如何将Vaadin 7.3.9集成到Eclipse中的Grails项目中?

时间:2015-01-30 09:04:33

标签: eclipse grails vaadin

我在使用Eclipse中的Vails集成到Grails项目时遇到了一些麻烦。

我正在使用Spring Tool Suite(版本3.6.3)和Grails(版本2.4.4)提供的Eclipse(版本4.4 Luna)。

我创建了一个Grails项目:

  • 文件 - >新 - > Grails项目

我正在阅读Vaadin Cookbook一书,作者说,为了在Grails项目中使用Vaadin,必须安装Grails的Vaadin插件。作者说应该:

  • 打开grails控制台并输入: grails> install-plugin vaadin

但是,从Grails 2.4.3开始不推荐使用它,并且插件必须像这样添加到BuildConfig.groovy文件中(基于本书的共同作者之一的本教程 - > {{3 (IntelliJIDEA用于链接的URL而不是Eclipse)):

// BuildConfig.groovy
// ...
grails.project.dependency.resolution = {
     //...
      plugins {
          //...
          compile ":vaadin:7.3.9"
          //...
      }
}

但是,那我该怎么办?他们在书中说grails-app/vaadin文件夹必须标记为源文件夹(Build Path -> Use as source folder),但我的Grails项目中没有这样的文件夹。

此外,从上面链接的InlliJIDEA教程中,作者说:

enter image description here

现在我尝试编辑UrlMappings.groovy文件以删除所有映射:

class UrlMappings {

    static mappings = {

    }
}

然后当我运行run-app命令时,我得到以下异常:

|Running Grails application
objc[42370]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
| Error 2015-01-30 11:33:56,213 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
    Line | Method
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by IntegrationException: Error activating Bean Validation integration
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by NoClassDefFoundError: javax/validation/ParameterNameProvider
->>  760 | defineClass in java.lang.ClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    142 | defineClass in java.security.SecureClassLoader
|    455 | defineClass in java.net.URLClassLoader
|     73 | access$100 in     ''
|    367 | run . . . in java.net.URLClassLoader$1
|    361 | run       in     ''
|    360 | findClass in java.net.URLClassLoader
|    424 | loadClass in java.lang.ClassLoader
|    269 | configure in javax.validation.Validation$GenericBootstrapImpl
|    111 | buildDefaultValidatorFactory in javax.validation.Validation
|    266 | run . . . in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by ClassNotFoundException: javax.validation.ParameterNameProvider
->>  372 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    361 | run       in     ''
|    360 | findClass in java.net.URLClassLoader
|    424 | loadClass in java.lang.ClassLoader
|    760 | defineClass in     ''
|    142 | defineClass in java.security.SecureClassLoader
|    455 | defineClass in java.net.URLClassLoader
|     73 | access$100 in     ''
|    367 | run . . . in java.net.URLClassLoader$1
|    361 | run       in     ''
|    360 | findClass in java.net.URLClassLoader
|    424 | loadClass in java.lang.ClassLoader
|    269 | configure in javax.validation.Validation$GenericBootstrapImpl
|    111 | buildDefaultValidatorFactory in javax.validation.Validation
|    266 | run . . . in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Error |
Forked Grails VM exited with error
|Server running. Browse to http://localhost:8080/vaadin-in-grails

最后说“服务器正在运行”,但事实并非如此,并且根据需要不会创建grails-app/vaadin文件夹。

我没有找到任何其他涵盖该主题的教程(特别是我正在搜索我链接的IntelliJIDEA教程的Eclipse版本,但没有找到它。)

所以,据我所知,我正在阅读的这本书涵盖了Grails的旧版本,其中插件是通过install-plugin已弃用的命令安装的,我无法使用它,因为我试图使用{{ 1}}指令没有成功,我在这里问SO的人。

如何解决此问题并开始使用Grails / Vaadin进行编程?

2 个答案:

答案 0 :(得分:1)

不要使用install-plugin方法。

将它放在BuildConfig.groovy的插件部分中:

 compile ":vaadin:7.4.1"

根据我对插件作者的理解,较新版本的Vaadin / Grails插件不再创建grails-app / vaadin目录。相反,您现在希望将您的vaadin代码放在​​典型的src / groovy或src / java文件夹中。

答案 1 :(得分:1)

Buddy,我遇到了同样的问题,但在阅读了很多关于Grails的Vaadin书并经过实验后,我遇到了解决方案,重要的是要提到我的grails项目正在使用这种配置,版本没有重大改变所以我相信它应该有效:

  • Grails 2.4.5
  • Vaadin 7.4.8,有点新,
  • Oracle Express for Database(这是不可知的)

从日志跟踪中,我看到以下这一行:

Caused by ClassNotFoundException: javax.validation.ParameterNameProvider

好的,首先,请转到BuildConfig.groovy并设置此值:

//BuildConfig.groovy

dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
    // runtime 'mysql:mysql-connector-java:5.1.29'
    // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
    compile 'javax.validation:validation-api:1.1.0.Final'
    test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
}

plugins {
    // plugins for the build system only
    build ":tomcat:7.0.55.2" // or ":tomcat:8.0.20"

    // plugins for the compile step
    //compile ":scaffolding:2.1.2"
    compile ':cache:1.1.8'
    compile ":asset-pipeline:2.1.5"
    compile ":vaadin:7.4.8"

    // plugins needed at runtime but not for compilation
    runtime ":hibernate4:4.3.6.1"
    runtime ":database-migration:1.4.0"
    //runtime ":jquery:1.11.1"
}

从上面的代码中你需要注意的是两件事:

  1. 插件部分正在使用hibernate4:4.3.6.1
  2. 在Dependencies部分我添加了以下行,从我的许多读物中有些人提到,由于从Hibernate3到Hibernate4的变化,规范中有一些变化以满足某些标准(这里javax.validation API已被弃用),所以这就是解决问题的方法:  编译'javax.validation:validation-api:1.1.0.Final'
  3. 现在在您的文件DataSource.groovy中,请注意以下几点:  1.你记得我设置项目使用Hibernate4,所以应该完成propper配置。

    //DataSource.groovy
    dataSource {
        pooled = true
        jmxExport = true
        username = "db_user"
        password = "db_password"
        dialect = org.hibernate.dialect.Oracle10gDialect
        driverClassName = 'oracle.jdbc.OracleDriver'
    }
    hibernate {
        cache.use_second_level_cache = true
        cache.use_query_cache = false
    //    cache.region.factory_class = 'org.hibernate.cache.SingletonEhCacheRegionFactory' // Hibernate 3
        cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' // Hibernate 4
        singleSession = true // configure OSIV singleSession mode
        flush.mode = 'manual' // OSIV session flush mode outside of transactional context
        jdbc.use_get_generated_keys = true
    }
    
    // environment specific settings
    environments {
        development {
            dataSource {
                dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
                //url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
                url = "jdbc:oracle:thin:@localhost:1521:xe"
            }
        }
        test {
            dataSource {
                dbCreate = "update"
                url = "jdbc:oracle:thin:@localhost:1521:xe"
            }
        }
        production {
            dataSource {
                dbCreate = "update"
                url = "jdbc:oracle:thin:@localhost:1521:xe"
                properties {
                   // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
                   jmxEnabled = true
                   initialSize = 5
                   maxActive = 50
                   minIdle = 5
                   maxIdle = 25
                   maxWait = 10000
                   maxAge = 10 * 60000
                   timeBetweenEvictionRunsMillis = 5000
                   minEvictableIdleTimeMillis = 60000
                   validationQuery = "SELECT 1"
                   validationQueryTimeout = 3
                   validationInterval = 15000
                   testOnBorrow = true
                   testWhileIdle = true
                   testOnReturn = false
                   jdbcInterceptors = "ConnectionState"
                   defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
                }
            }
        }
    }
    

    在hibernate部分中,你必须设置值:

    cache.region.factory_class
    

    在我的情况下,我正在使用Hibernate4,所以你应该使用相同的值。

    来源: 检查这个项目:https://github.com/vaadin-on-grails/sass-compilation并且不要忘记在Grails上购买Vaadin这本书,它有很多相关的信息。