I am experimenting with Spring Roo in a new GWT application. The Spring Roo GWT support is some way off ready for real use just yet, so I want to build the GWT stuff by hand using as much of the GWT 2.1 MVP stuff as possible. The problem I have is that Spring Roo "notices" my MVP-related classes and generates a whole lot of extra (broken) stuff for my entities.
How can I get Spring Roo to ignore the GWT side of my project?
"I want to build the GWT stuff by hand using as much of the GWT 2.1 MVP stuff as possible"
If you're building GWT by hand, it sounds like you're interested in using Spring Roo to generate your data model code — but don't want (or need) any of Spring Roo's web controller code. If that's the case then you can separate your project into two modules:
A module containing model and persistence code that is created by Spring Roo
A GWT web application that you create by hand.
Make the first (Roo) module a dependency of the second (GWT) module. Basically you're using Roo to create a JAR library that's used by your web application. As long as you don't run the controller command the Roo won't add any web application code to your module.
I renamed my gwt.scaffold package to gwt.shell and gwt.request to gwt.req and Spring Roo is leaving my stuff alone.
Related
I have a large application with a database, Swing UI etc. Now I want to add a REST API for this application. Spring Boot allows easy generation of a REST API with useful features such as OpenApi documentation and authentication.
However when I run the Spring Boot application from within the large non Spring Boot application the Spring Boot application gets confused by the dependencies of the parent application and fails to run.
So my requirement is this: run a Spring Boot application from withing a non Spring Boot application without dependency interference from the parent application. I am currently running the Spring Boot application by adding the executable jar as a dependency and then calling
org.springframework.boot.loader.JarLauncher.main(new String[0]);
to run the Spring Boot application. I am not set on this way of doing it and any suggestions will be greatly appreciated.
Spring is a huge collection of highly configurable software libraries that can be used to setup (among other things) REST API endpoints and OpenAPI documentation and UI.
Spring Boot is a project to simplify the process of using these libraries by applying an opinionated view of how to run them within a standalone process.
By asking how to run a Spring Boot application within a larger application you are trying to get the benefit of the opinionated setup while violating the assumptions that the setup is based on. I guess in theory it might be possible using some sort of handrolled classloader isolation, but once you've solved the dependency problem you'll probably end up with class version conflicts, issues with configuration locations, etc. In short if it is possible at all the effort of doing so would negate the benefit.
There are two ways of resolving the issue.
Use Spring Boot to build your API as a standalone process. Configure the new process to talk to the same database as the existing application. If neccessary factor out any code common to both the existing application and the API (JPA entities, DAO classes etc) into a shared library. If you go with this option you will have the overhead of having to manage multiple kinds of process in your production environment, which is more complex - but has advantages in terms of decoupling scaling, release cycles, restart times. See the debate on microservices (https://martinfowler.com/articles/microservices.html).
Use the Spring libraries that provide REST and OpenAPI features as part of your existing application, without using Spring Boot. You'll need to have SpringMVC set up in order to use #RestController annotated classes. If your existing application is a web application that's not too bad (https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mvc.html). If it's not run in a webserver already you'll have to launch the SpringMVC framework in an embedded webserver (https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat). There's a good article on adding OpenAPI to an MVC application here: https://www.baeldung.com/spring-rest-openapi-documentation.
you can simply exclude auto-configure dependencies. Here is an informative link https://www.marcobehler.com/guides/spring-boot
Here is a code snippet of how to exclude when applications get started.
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(PayPalApplication.class, args);
}
}
or the other ways
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
I want to share another Spring Framework dependencies https://www.marcobehler.com/guides/spring-framework
Is it possible to take a project that I've been working on , import it into Spring STS and apply all the goodies that STS provides for easy Spring development to the project? For example, I'd like to be able to take this existing project which is not a Spring MVC application at the moment and treat it as though it was created as a Spring MVC template (kind of like wrapping the project in an STS MVC template). I hope this makes sense :)
As far as I am aware you can't decorate an existing project with Spring goodies just by importing it in to STS.
The best you can do is import and add the Spring project nature. This can be found by right-clicking on the project and selecting Spring Tools --> Add Spring Project nature.
Please advise me a project where I can see how to use Spring MVC and Hibernate together in the right way. I'm new to these frameworks.
Appfuse has a Maven archetype for this stack.
Strongly suggest you have a peak.
Alternatively the book Spring in Action was a great resource for me in learning spring and hibernate/spring interaction - use Annotation driven transaction management as well and you have a really great start.
see here: http://appfuse.org/display/APF/Using+Spring+MVC
appfuse-basic-spring is the basic project archetype.
Using maven modules is a better practice. ie)
appfuse-modular-spring
If you install m2e (maven 2 eclipse plugin) creating a new maven project will allow you to select the archetype.
better answer:
If I was going to recommend HOW to learn these technologies, I would say learn how to build a hibernate/maven/xml project first by following this:
http://www.mkyong.com/hibernate/quick-start-maven-hibernate-mysql-example/
Then learn how to use spring for dependency injection with maven/hibernate and xml:
http://www.mkyong.com/spring/maven-spring-hibernate-mysql-example/
Take special note of layering of the bo/dao pattern and how you use interfaces but wire in implementations with spring di - this is crucial for writing quality code
Next check hibernate annotations and annotation driven transactions:
http://www.springbyexample.org/examples/hibernate-transaction-annotation-config.html
http://www.springbyexample.org/examples/hibernate-transaction-annotation-config-code-example.html
http://www.mkyong.com/hibernate/maven-hibernate-annonation-mysql-example/
Finally, you can learn your mvc framework of choice. I actually recommend struts2 but it won't matter much. use spring DI by implementing interfaces and wiring implementations at runtime for you actions/controller. If you don't understand this how, you will after the hibernate/spring tutorials. Spring in action will be a good reference to keep on your desk but will take a few weeks to digest as you learn. Good luck! You can do it - I did and am now working as a java dev!
the petclinic app includes these, and many more things
spring-roo can create a skeleton project using these technologies for you.
If you are new to Spring MVC and Hibernate, I advice you to follow the Spring MVC step by step guide. The only problem with this is the version, the guide uses version 2.5 and the current release is 3.1.x, but it's a very good starting point to accumulate knowledge.
Spring MVC quickstart archetype provide simple spring-mvc and hibernate configuration.
How does one go about customizing the GWT user interface that Spring Roo automatically generates?
Am I supposed to change the Roo-generated source files? If so, will that not be clobbered the next time Roo runs?
Or do I need to configure something in Roo and then rebuild the GWT sources?
In this particular case, the column widths of the domain object list view need to be adjusted.
For as far as I know, this is indeed not possible yet in Spring Roo. As you rightfully stated, the by Spring Roo generated files will be regenerated by Spring Roo when you alter your entities. There are some solutions, but these all are but small workarounds and don't offer the actual programming experience you'd expect or want. The Spring Roo team (and community) has already addressed this issue though and is working hard to solve this. So expect this to be improved real soon. For more information, check the following links to the Spring Roo Forum and Spring Roo JIRA:
Spring Roo Forum thread: Roo GWT customization
Spring Roo JIRA issue: Roo update is too destructive
Spring Roo JIRA issue: Manual Created Request Interfaces get deleted
May I humbly suggest Metawidget? It generates Spring MVC, GWT and other interfaces at runtime, so there is no regeneration step (and nothing to get 'clobbered') as your entities change.
If you want to modify a ui.xml file generated by ROO, just rename it and refer to it in the .java file.
e.g You want to modify the file PizzaDetailsView.ui.xml:
Rename it to PizzaDetailsViewPrime.ui.xml
Then add this line just before the interface Binder declaration:
#UiTemplate("PizzaDetailsViewPrime.ui.xml")
What if you don't want to start a separate project for grails but instead sneak it into an existing webapp?
I have to build an admin interface/crud for some new entities and thought it would be a perfect way to learn grails.
I'm trying to make one application with a Grails app and a Spring app.
I've tried to sneak the Grails App into the Spring one, but this is "impossible". It's easier to sneak the Spring app into the Grails app. Grails knows what Spring is, but Spring has no idea of what Grails is.
In this article you can find useful information about how to use your hibernate mapping files or annotations in Grails, so you don't have to remap everything. Also you can use all your java clases (put them into src/java). You can put the beans defined in the ApplicationContext.xml in conf/spring/resources.xml. You can leave them in ApplicationContext, but I've had some problems.
I don't have ended the job (almost) and it looks good.
It would be hard to "sneak it in" unless the existing app has the correct dir structure that maps exactly to how grails likes it - after all, convention over config is where the power of grails comes from.
You can try doing the admin interface as a "seperate" app to the original/existing spring app, and map the existing database to the grails domain objects. though i m not sure how you would run them side by side easily without more information on the existing app. It is possible definitely though.
I agree that building your admin interface is a good exercise to learn Grails, and also agree with the previous answer that Grails is difficult if not impossible to integrate with an existing Spring application. You could probably get it done, but the headache would not be worth it.
Grails is built on top of Hibernate for its ORM, so if you're already using Hibernate with this Spring app you can work this to your advantage. It's not too difficult to configure a Grails app to use pre-existing Hibernate models, and this is explained well in Grails documentation.
So, I'd recommend building up your admin console as an independent Grails app but make use of the Hibernate models you already have, if in fact you've used Hibernate.