I use grails 2.0.0.rc3, when I install PayPal plugin I have this error:
Error Compilation error: startup failed:
/Users/sartre/.grails/2.0.0.M1/projects/testapp/plugins/paypal-0.6.4/grails-app/controllers/org/grails/paypal/PaypalController.groovy: -1: The return type of java.lang.Object notify() in org.grails.paypal.PaypalController is incompatible with void notify() in java.lang.Object
. At [-1:-1] # line -1, column -1.
1 error
How can I fix it?
Many thanks for any idea
Incompatibility change in grails 2.0!!
It seems that it is related to a small change in grails 2.0.
It is now possible to define controller actions as methods instead of using closures as in previous versions of Grails. (from official doc : http://grails.org/doc/2.0.x/guide/introduction.html#webFeatures)
It behaves like the closure notify in PaypalController overrides the Object.notify method.
If you rename notify in notifyPaypal, it should work.
Related
I'm trying to upgrade Grails 2.3.7 project to Grails 3.2.3. In 2.3.7, I used custom constraints and register them in /conf/Config.groovy using:
org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint('description', my.validation.DescriptionConstraint)
Then I can use something like this in domain:
static constraints = {
approvedDate(description: '>= applyDate')
}
However, in Grails 3.2.3, When I put above command (and remove org.codehaus.groovy from package name) in /conf/application.groovy I got following error:
Error occurred running Grails CLI: No signature of method: groovy.util.ConfigObject.registerNewConstraint() is applicable for argument types: (groovy.util.ConfigObject, groovy.util.ConfigObject) values: [[:], [DESCRIPTION_CONSTRAINT:[:]]]
I've notice that validation class is somewhat changed in Grails 3. However using constraint class from Grails-validation still got the same error.
All validation plugins I found were long abandoned before Grails 3. And I can't find any document for register new constraint in Grails 3.2.
Calling ConstrainedProperty.registerNewConstraint in /grails-app/init/BootStrap.groovy works. (tested with Grails 3.2.4)
class BootStrap {
def init = { servletContext ->
grails.validation.ConstrainedProperty.registerNewConstraint('description', my.validation.DescriptionConstraint)
// The rest of bootstrap code
}
}
Note. Previously, I call it from main() in /grails-app/init/Application.groovy. It works for running application. However, it does not work with integration test.
Another way you can create the runtime.groovy under config and register your constraints in the runtime.groovy as in grails 2.x.x:
org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint('description', my.validation.DescriptionConstraint)
Forgive me for my English. Actually I want to use A template profiler plugin in grails 2.4.3. But it is unable to install in this grails version. It is available for the grails version 1.3.2. And I want to use it for grails 2.4.3. When I am trying to install. It shows an error
| Error Compilation error: startup failed:
C:\Project\target\work\plugins\profile-template-0.1\grails-app\services\profile\te
mplate\ProfileTemplateService.groovy: 5: unable to resolve class
org.codehaus.groovy.grails.commons.Configurat ionHolder # line 5,
column 1. import
org.codehaus.groovy.grails.commons.ConfigurationHolder ^
C:\Projects\target\work\plugins\profile-template-0.1\grails-app\services\profile\te
mplate\ProfileTemplateService.groovy: 8: unable to resolve class
org.codehaus.groovy.grails.commons.Configurat ionHolder # line 8,
column 26.
boolean isRecording = !(ConfigurationHolder.config?.profile?.template?.disabled as Boolean)
^
2 errors
Can anybody help me to get me out of this. Or You can suggest me another alternate option for this.
Thanks in advance.
If you have access to the source code of the plugin you could follow this:
In Grails 2 we no longer use ConfigurationHolder we use GrailsApplication.getConfig() instead. In the ProfileTemplateService add field GrailsApplication grailsApplication (Spring will inject it during app boot up) and change the:
ConfigurationHolder.config?.profile....
to
grailsApplication.config.profile...
Your service class should look like:
class ProfileTemplateService {
GrailsApplication grailsApplication
def method() {
a = grailsApplication.config.profile
}
}
Obviously there can more hoops to jump through before you actually make the plugin work.
I decided to return to Dropwizard after a very long affair with Spring. I quickly got the absolute barebones REST service built, and it runs without any problems.
Using Dropwizard 0.7.1 and Java 1.8, only POM entries are the dropwizard-core dependency and the maven compiler plugin to enforce Java 1.8, as recommended by the Dropwizard user manual
However, as soon as I try to add an Optional QueryParam to the basic controller, the application fails to start with the following error (cut for brevity):
INFO [2015-01-03 17:44:58,059] io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources:
GET / (edge.dw.sample.controllers.IndexController)
ERROR [2015-01-03 17:44:58,158] com.sun.jersey.spi.inject.Errors: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public java.lang.String edge.dw.sample.controllers.IndexController.index(java.util.Optional) at parameter at index 0
Exception in thread "main" javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-6c2ed0cd#330103b7==com.sun.jersey.spi.container.servlet.ServletContainer,1,false
The code for the controller is as follows:
#Path("/")
public class IndexController {
#GET
#Timed
public String index(#QueryParam("name") Optional<String> name) {
String saying = "Hi";
if(name != null && name.isPresent()) {
saying += " " + name.get();
}
return saying;
}
}
If I remove Optional from the mix, the application runs just fine. I replace the Optional-specific code with null checks and it works perfectly.
Am I missing something fundamental here? Both Google Guava Optional and java.util.Optional fail with the same error. (And yes, I did narrow it down to the Optional object)
A quick Google/SO search yielded nothing useful, but feel free to point me to a resource I may have missed
Thanks in advance!
Moments after posting this, I found that the issue was my use of Java 1.8. If using Java 1.8, I have to add the Java8Bundle to my app:
POM Entry:
<dependency>
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-java8</artifactId>
<version>0.7.0-1</version>
</dependency>
And code in the Application class:
#Override
public void initialize(Bootstrap<SampleConfiguration> bootstrap) {
bootstrap.addBundle(new Java8Bundle());
}
See: https://github.com/dropwizard/dropwizard-java8
This enables both Google Guava Optional and java.util.Optional to work just fine.
If I revert to Java 1.7 and use the Google Guava Optional, it works just fine as well and I don't have to include the Java8Bundle. I'll opt for the Java8Bundle for now, though, as using Java8 features is lucrative for me :)
Cheers!
I'm trying to use the latest version of the grails ehcache plugin (1.0.4) in my grails application, however when I add the plugin as a dependency in BuildConfig.groovy I get a compile error on startup:
| Error Compilation error: startup failed:
Compile error during compilation with javac.
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:202: error: ReloadableCacheManager.ProxyEhcache is not abstract and does not override abstract method getSearchesPerSecond() in Ehcache
protected class ProxyEhcache implements Ehcache {
^
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:805: error: getStatistics() in ReloadableCacheManager.ProxyEhcache cannot implement getStatistics() in Ehcache
public StatisticsGateway getStatistics()
^
return type StatisticsGateway is not compatible with Statistics
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:663: error: cannot find symbol
return getUnderlyingEhcache(name).getSearchAttributes();
^
symbol: method getSearchAttributes()
location: interface Ehcache
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:660: error: method does not override or implement a method from a supertype
#Override
^
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:758: error: cannot find symbol
return getUnderlyingEhcache(name).calculateOnDiskSize();
^
symbol: method calculateOnDiskSize()
location: interface Ehcache
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:755: error: method does not override or implement a method from a supertype
#Override
^
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:765: error: cannot find symbol
return getUnderlyingEhcache(name).getAll(arg0);
^
symbol: method getAll(Collection)
location: interface Ehcache
where CAP#1 is a fresh type-variable:
CAP#1 extends Object from capture of ?
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:761: error: method does not override or implement a method from a supertype
#Override
^
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:770: error: cannot find symbol
return getUnderlyingEhcache(name).hasAbortedSizeOf();
^
symbol: method hasAbortedSizeOf()
location: interface Ehcache
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:768: error: method does not override or implement a method from a supertype
#Override
^
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:777: error: cannot find symbol
getUnderlyingEhcache(name).putAll(arg0);
^
symbol: method putAll(Collection)
location: interface Ehcache
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:773: error: method does not override or implement a method from a supertype
#Override
^
/Users/rcgeorge23/Documents/workspace/grails-cache-ehcache/src/java/grails/plugin/cache/ehcache/GrailsEhCacheManagerFactoryBean.java:783: error: method putIfAbsent in interface Ehcache cannot be applied to given types;
return getUnderlyingEhcache(name).putIfAbsent(arg0, arg1);
^
required: Element
found: Element,boolean
Has anyone else had this problem? I notice the ehcache plugin is still being maintained, so I guess it works with current versions of grails, however I can't seem to get it to work for me. I've also tried cloning the latest commit from the grails-ehcache project in github and referencing this as a local plugin project, but I still get the same compile error.
I'm using Grails 2.3.7.
EDIT 1:
I was able to get my app to start up using version 1.0.0 of the ehcache plugin, although I imagine I'm probably missing out on some important enhancements if I use this version...
EDIT 2:
Ok for now, I've just cloned version 1.0.0 from github and cherry picked the fix for the TTL defect (https://jira.grails.org/browse/GPCACHEEHCACHE-6). It'd be good to find out why I can't get 1.0.4 working, but I have a workaround for now.
It works for me with a basic 2.3.11 app, so I'm guessing that something else is bringing in an older version of the ehcache jar. You'll probably see that if you run grails dependency-report.
The 1.0.4 plugin depends on net.sf.ehcache:ehcache:2.9.0 but most other plugins that depend on Ehcache haven't been updated to the most recent versions, so you'll probably see that you also have a dependency for net.sf.ehcache:ehcache-core:2.4.8, but the version might be off a bit. Notice that they dropped the "-core" from the name, which could also be contributing to this because unless the group and name are exactly the same, one jar cannot evict another. So it's possible for two people to have both jars in the classpath, but they end up in the opposite order, and it works fine for one because the newer jar's classes are loaded, but not the other because the the older classes are loaded.
You'll get a better dependency report if you switch temporarily from
grails.project.dependency.resolver = "maven"
to
grails.project.dependency.resolver = "ivy"
in BuildConfig.groovy - the maven resolver only generates output to the console, but the Ivy output also includes HTML output.
If you can't resolve this, create a small separate test app and configure it so it fails the same way - you probably just need to copy BuildConfig.groovy from your app. Create an issue at https://jira.grails.org/browse/GPCACHEEHCACHE and I'll take a look. If all you need to do is change BuildConfig.groovy, attach that to the issue, otherwise run grails bug-report and attach the zip it creates.
I get repetitive method name/Signature compilation failure when i try to use i18nFields in my domain class to support multiple languages.
Grails Version : 2.3.7 ( I tried with 2.3.4 and got the same issue and upgraded)
Documentation from Grails followed for this was http://grails.org/plugin/i18n-fields
My Domain class looks like
package com.sampleapp.domain
import i18nfields.I18nFields;
#I18nFields
class Products {
def name
static constraints = {}
static i18nFields = ['name']
}
My Config.groovy has the below line included to specify the locale
// internationalization support - testing
i18nFields {
locales = ['en','es']
}
BuildConfig.groovy plugin definition
plugins {
// plugins for the build system only
build ":tomcat:7.0.47"
// plugins for the compile step
compile ":scaffolding:2.0.1"
compile ':cache:1.1.1'
// plugins needed at runtime but not for compilation
runtime ":hibernate:3.6.10.6" // or":hibernate4:4.1.11"//
runtime ":database-migration:1.3.8"
runtime ":jquery:1.10.2.2"
// compile ":jquery-ui:1.10.2.2"
runtime ":resources:1.2.1"
// Uncomment these (or add new ones) to enable additional resources capabilities
runtime ":zipped-resources:1.0.1"
runtime ":cached-resources:1.1"
//runtime ":yui-minify-resources:0.1.5"
compile ':platform-core:1.0.RC6'
compile ":cache-headers:1.1.5"
runtime ':spring-security-core:2.0-RC2'
// internationalization
compile ":i18n-fields:0.8.1"
}
The compilation error is
grails-workspace\Test\grails-app\domain\com\sampleapp\domain\Products.groovy: -1: Repetitive method name/signature for method 'void setName_es(java.lang.String)' in class 'com.sampleapp.domain.Products'.
# line -1, column -1.
The Error is repeated for the name property for both en and es locales twice.
There is no error if i remove the i18nFields annotation and the sample app worked fine before this. I verified GGTS repetitive method name/signature error in controllers post for similar error in controller. I have also verified to ensure that groovy version is correct and in my case it is 2.1
Can somebody please give me any pointers on where i should look to resolve this issue.
This problem shows up when you are trying to use Java > v7 with any version of Grails < 2.3.7. Either downgrade your jvm or upgrade your grails.
Thanks for trying (and for making me know via github ;) )
The issue was known but hadn't been tackled yet.
The previous answer (commenting out methods) is not exact, event though it follows the right track, because the problem comes from new changes in Grails that will cause a collision in getters and setters.
The solution I've found is to separately create the property and the getter/setter, and it seems to work.
I'm releasing a new version as soon as it can be fully tested in a project, but code is already available in https://github.com/jorgeuriarte/grails-i18n-fields-plugin/tree/redis_integration (version 0.9-redis-SNAPSHOT) in case you want to use it.
Probably it has something to do with the new Binding mechanism in grails 2.3. Maybe the getters and setters are set automatic now?
When I comment out these two lines in ClassI18nalizator.groovy the error disappears. It seems to work at least partly. I can use the fields in scaffolding. It's not a real solution but maybe a hint for someone who understands grails better than me.
private def getSetterMethod(field) {
// setter should return void. that's why the return statement.
//return new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.setValue(this, '${field}', value); return;").pop();
}
private def getGetterMethod(field) {
//new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.getValueOrDefault(this, '${field[0..-7]}', '${field[-5..-1]}')").pop();
}
After that I run into a second issue:
No signature of method: groovy.util.ConfigObject.contain() is
applicable for argument types: (java.lang.String) values: [en_US]
I solved it by adding redisLocale to Config.groovy
i18nFields {
locales = ['de_DE', 'en_US']
defaultLocale = "en_US"
redisLocales = ['de_DE', 'en_US']
}