Используйте классы предметной области из плагина

я в настоящее время пробую первый раз Grails 3.

Я создал плагин (который должен содержать несколько классов предметной области) и простое приложение.

Теперь я получаю следующую ошибку:

Caused by: java.lang.IllegalStateException: Either class [de.foo.Author] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.

Класс домена автора:

class Author { 
  String name 
}

Я отключаю Grails 3.2.9 со следующими зависимостями:

Плагин

compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
console "org.grails:grails-console"
profile "org.grails.profiles:web-plugin"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.3.Final"
compile "org.hibernate:hibernate-ehcache:5.1.3.Final"

compile 'org.grails.plugins:spring-security-cas:3.0.0'
compile 'org.grails.plugins:spring-security-core:3.1.2'

compile "org.apache.poi:poi:3.16"
compile "org.apache.poi:poi-ooxml:3.16"
compile "org.apache.poi:ooxml-schemas:1.0"

compile 'org.grails.plugins:wkhtmltopdf:1.0.0.RC7'

Приложение

compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.3.Final"
compile "org.hibernate:hibernate-ehcache:5.1.3.Final"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.1"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
runtime "com.h2database:h2"

compile "de.foo:bar:0.1"

runtime 'com.bertramlabs.plugins:asset-pipeline-grails:2.14.3'
assets 'com.bertramlabs.plugins:less-asset-pipeline:2.14.3'

runtime "mysql:mysql-connector-java:5.1.29"

Ребята, у вас есть какие-либо предложения или ответы для меня, как хранить классы домена в плагине и использовать его в некоторых приложениях?


person YAT    schedule 12.07.2017    source источник
comment
Когда вы получаете эту ошибку? И чтобы быть на 100% уверенным: одна и та же версия Grails в плагине и в приложении?   -  person Daniel    schedule 12.07.2017
comment
да одинаковая версия в плагине и в приложении. Я получаю эту ошибку при запуске приложения.   -  person YAT    schedule 13.07.2017
comment
Ну, версия Grails была такой же, но версия GORM была другой. установка обоих на одну и ту же версию решила проблему   -  person YAT    schedule 13.07.2017


Ответы (1)


Для ошибок GORM версии должны быть одинаковыми. Что касается других вещей, связанных с Grails, версии groovy обычно должны быть одинаковыми для двоичной совместимости. Хотя не требуется на 100% сохранять одинаковые версии во всех случаях, в grails 3 это гораздо более необходимо, чем в grails 2, и, вероятно, это просто лучшая практика на данный момент.

person Daniel    schedule 13.07.2017
comment
Хотя не требуется на 100% сохранять одинаковые версии во всех случаях, в grails 3 это гораздо более необходимо, чем в grails 2. На самом деле это не так. Grails 3 позволяет легко (намеренно) смешивать и сочетать разные версии вещей. На самом деле, в последних выпусках Grails 3 мы вытащили версию GORM в файл свойств специально, чтобы вы могли обновить эту зависимость независимо от остальной части приложения. - person Jeff Scott Brown; 14.07.2017
comment
Тогда плохая формулировка с моей стороны. Необходимо (или лучше всего), чтобы все плагины, а также ваше приложение имели одну и ту же версию gorm. Либо та же версия groovy, либо грааль. Например, в Grails 2 не было большой проблемы (обычно) иметь плагин на 2.3.9 и приложение на 2.5.1. Теперь... это большое дело. - person Daniel; 14.07.2017
comment
К счастью, теперь намного ПРОЩЕ выбрать другую версию, я согласен. Это немного неудобно, если вы используете сторонний плагин, который не выбрал эту версию, но это обсуждение для другого форума. :-) - person Daniel; 14.07.2017