I know I can do it manually but is there any grails create-service counterpart for removing a service?
No, there is not. As others have said, removal is more dangerous than creation. Either use an IDE, or remove the service manually after checking for any usages.
Related
I recently learned how to register custom grails artifacts (I need it for dynamic controllers in my application) using grailsApplication.addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass) and it works fine, but now I realized that I also want to be able to unregister them.
Unfortunately, interface GrailsApplication provides no clear way to do so and it seems that unregistering unwanted dynamically registered grails artifacts can only be done by restarting the whole application.
Maybe I'm missing something and an artifact can be removed from an application without having to restart the app?
Thank you
You can always rebuild the GrailsApplication. That throws away all artefacts and loads the default ones. That obviously means you'd have to addArtefact the artefacts you want to keep again.
Other option is access the loadedClasses set (which is protected) and make the changes manually and then call populateAllClasses to make available (this method is protected too).
I am trying to figure out how to disable javamelody grails plugin completely. Following http://www.grails.org/plugin/grails-melody, I set javamelody.disabled = true in GrailsMelodyConfig.groovy. For some reason, this disables monitoring in a sense that I cannot navigate to myapp/monitoring to view info. More debugging showed that even if I disabled it, it is still calling doWithDyanmicMethod which adds invokeMethod on each services.
Is there something else I am missing? If it adds invokeMethod on each services, this defeats the point of disable.
According to the documentation:
The parameter disabled (false by default) just disables the
monitoring. This allows for example to disable the monitoring
temporarily or only on some servers, from the tomcat context or from
system properties without modifying the web.xml file neither the war
file of the monitored webapp.
But maybe you can disable the whole monitoring by using the 'url-exclude-pattern' option. Hope this helps.
This could be disabled all meta programming by adding context-param javamelody.disabled in web.xml. So to avoid calling doWithDyanmicMethod part.
I'm wondering where utility code can be placed, that doesn't cause a restart of container. Updating controllers doesn't cause a container restart & the updated code is available to run (great), but I wanted a more general library/utility place for my utility code.
Putting the code in /utils or in src/groovy does cause a restart on save, at least using Intellij, but I imagine this is the same regardless of where Grails is developed.
Perhaps you have some general info/insights on how Grails does this -- includes new code but doesn't need to restart the container, if that's only special to controllers?
(v. 1.3.7)
You're out of luck out of the box unless you want to use 2.0. The alternative is to turn off auto-reloading and add in something like jrebel. See this blog for details.
I am developing a Grails application (with Grails 1.3.7). In service layer, I did not use the command 'create-service' to create my service but do it manually.
As the result, my service was not auto initialize in controllers and other services, and it did not handle transaction.
But I do not know where is the differences from create service by command with by manual? Because I do not see any configuration file which figure out this? (I mean in traditional Spring, we always have some configuration files which specify all beans in applications, but in Grails is not).
I want to fix this issue and commit to SVN server my fix, but I do not want to delete the old service and commit the new one which is created by Grails command. So could you please help me:
1. explain what is the differences from create service by command with by manual?
2. how to change the the service created by manual to service created by command without replacing the old one?
Thank you so much!
explain what is the differences from create service by command with by manual?
Assuming you put your service in grails-app/services and followed the naming convention using a postfix of Service The only difference is that you get a nice template that looks like
class SomeService {
boolean transactional = true
def someMethod() {
}
}
and it automatically creates a unit test with the name SomeServiceTests. That is it. BTW transactional defaults to true if you do not include it.
how to change the the service created by manual to service created by command without replacing the old one?
There is nothing to do assuming you followed the conventions. If you did follow the conventions and you are still experience problems please update your question with more details such as how are you trying to use your service and a example of your service.
As long as you put your class in the grails-app/services directory, it should act just like any other service (and work as a spring bean).
If you put it in src/java or src/groovy, it's not considered a service (and not loaded as a service artefact by grails). It could still be a spring bean, but you'd have to manually add it to the resources.groovy file.
Also note that the Grails autowiring of the beans must be exact, so if you have MyService and you want to use it in the controller, make sure you have "def myService" or "MyService myService." If you would prefer different names of your member variables, you can also use the Spring Autowired annotation directly, though I've only tried autowiring grails types (e.g. a grails service) autowired to a bean I declared in resources.xml
If you put services, or any other bean in the resources.xml or resources.groovy files, they will also be autowired intro controllers, other services, etc.
It's best to think of Grails as "rapid Spring", so the autowiring, transactions, etc all are backed by Spring configuration and such.
I have an app that runs as a service, and I'd like it to be able to check a URL to see if a new version is available, and if so to download and install it. I can manually hack something together, but would be great if I could create an MSI package to update the service, and any other components that are part of my distribution. I'd also like it to be done without any UI, so the user is unaware of the update.
Are there any good solutions for this?
This could be tricky depending on what your update might want to do.
If you intend on deleting and re-installing the service, this may require a reboot, which will certainly be visible to the user.
In order to replace the components of the service, the service has to be stopped first. If your service itself is detecting the update availability, it may have to kick off another process to stop the service, run the installer/updater and then restart the service.
Try installer.codeeffects.com. It has this feature.
You could try MEF (http://www.codeplex.com/MEF) and use
[Import("http://someUrl/someComponent")]
public ISomeComponent SomeService;
Its not actually an auto update, but the service could be always up to date. I am not sure if it works.. its just an idea :-)