I'm upgrading a grails 1.3.6 app to 2.2.4. In 1.3.6, the app is accessed by hitting localhost:8080/APPNAME. This then renders the file in grails-app/views/index.gsp.
After upgrading the app to 2.2.4, hitting localhost:8080/APPNAME' returns an error of :
HTTP Status 404 - "/index.gsp" not found..
My URLMappings file is as follows:
class UrlMappings
{
static mappings =
{
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
//"500"(view:'/error')
"500"(controller: 'pacErrors', action: 'handleErrors')
}
}
I am able to access controllers directly via URL calls, so the server does appear to be up and running.
It all seems correct, sometimes when confronted with weird behaviours after an upgrade, I find the best fix is a "grails clean", and make sure that the app is indeed migrated to 2.2.4 by running "grails upgrade".
If this does not work, try creating a new application directly with grails 2.2.4 to test it out. If you cannot spot the problem after that, you could copy your existing app into the new one.
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)
I am sitting in front of a Grails 3.1.4 Application. The build.gradle file looks like this:
buildscript {
...
}
version "01.01.12.99"
...
ext {
...
}
repositories {
...
}
dependencyManagement {
...
}
dependencies {
...
}
From one of my Service Classes I want to access the version variable. Is this somehow built in into Grails or am I trying to do something impossible? Are there ways to load this variable from a Service class?
I searched a bit and found this, but it accesses the Grails version not the project version.
Well, I recently started using Grails 3. Here I got the solution:
println System.properties.getProperty("info.app.version")
And you will get "01.01.12.99". This is working on Grails 3.1.8 for me.
Another way to achieve this (in addition to the solution provided by Shashank Agrawal) is relying on grailsApplication bean, with the following code:
grailsApplication.config.getProperty('info.app.version')
I tested this with Grails 3.1.9 and 3.2.7.
I am following a book example (Grails in Action 2nd edition) which is based on Grails 2.* but I am using the new Grails 3.0.1.
When I create a domain class that looks like:
package qotd
class Quote {
String content
String author
Date created = new Date()
}
I get an Exception thrown whenever I try to interact with the DB through the groovy console.
org.springframework.dao.DataAccessResourceFailureException: Could not obtain current Hibernate Session;
Caused by: org.hibernate.HibernateException: No Session found for current thread
I have tried to add #Transactional to the domain class and also swith to a lower JDK version(7) but none of them works.
I have also tested with Grails 3.0 and results are same.
If I downgrade to Grails 2.5.0 it works so it is a Grails 3.* issue. Gradle could be the issue.
I wrapped everything inside a transaction for Grails 3
qotd.Quote.withTransaction {
new qotd.Quote(author: 'Larry Wall',
content: 'There is more than one method to our madness.').save()
}
I have an application that was working fine until I added code to run a JasperReport. The error is the well known
Target Unreachable, identifier 'studentBean' resolved to null
After adding the code needed to run a JasperReport, the particular page that uses that bean (StudenBean) started to show such an exception before it even shows. After a process of commenting/uncommenting lines of code, I could isolate de precise line that brings the problem. It's shown below:
private void gerarRelatorioPDF(List<Student> students, InputStream report, OutputStream pdf) {
JRDataSource jrds = new JRBeanCollectionDataSource(students);
try {
JasperRunManager.runReportToPdfStream(report, pdf, null, jrds); // <<-- Here!!!
} catch (Exception e) {
e.printStackTrace();
}
}
It's the line that generates a PDF stream from a JasperReport definition. This method is private because it's called by another public method. The public method is the action of a <p:commandButton/> in the page, so this button is not even being clicked, because the exception prevents the page to render.
If I comment that line of code, the page renders ok and I can click the button, but obviously no report will be generated.
Any ideas how to fix it?
After some study, I decided to modify my POM.xml (Maven script) to include JasperReports 6.0.0. Previously I had only installed JasperReports 6.0.1 plugin in Eclipse, created and configured the report.
When we add a new report to a project, Eclipse automatically adds the path to JasperReports libraries to the class path, so the project compiles fine, but it seems that some other dependencies are not added and, specially, not deployed to the application server (in my case JBoss AS 7.1).
After updating the POM.xml to include JasperReports, everything started to work as desired.
I need some help, I am trying to make an controller using Google Analytics API, but using:
statsController.groovy
/**************************************************************/
import com.google.gdata.client.analytics.AnalyticsService
class StatsController {
def myService
def stats(){
myService = new AnalyticsService("example-App");
}
}
/************************************************************/
error Message:
ClassNotFoundException occurred when processing request: [...]
com.google.common.collect.Maps
I ve tryed adding to the buildpath the "gdata.analytics*.jar", "google-collect-1.0.jar", "guava.jar" and "jsr305.jar" but without results, the error always says that i described or NotDefClassError ocurred when processing request: [...] com.google.gdata.client.analytics.AnalyticsService.
I need to solve.
The handling of JARs is kept pretty easy in grails. If you don't use stuff like maven you can just copy your JARs into the lib folder in the root directory of your grails application.
Try to put them there and see if it solves the problem.
Further: what IDE do you use? IntelliJ for instance recognize JARs within the lib folder instantly. So you should see the effects in your IDE already.