Good project with spring-mvc and hibernate - java

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.

Related

Spring Data in non-Spring Project

I want to use Spring Data Cassandra in a non-Spring Project for Object Mapping. The project is not using Spring Boot or any other Spring component. Is this a good practice or I am doing it the wrong way?
P.S-Things are working fine but just wanna know If I'm on right track.
The usage of Spring Data in a non Spring project is frequent (mostly in old projects). The real question is, how to integrate it properly in your current architecture.
It's not a good or bad practice, it's a technical chose which must be in adequacy with your functional and technical requirements.

Is there an easy way to map entities to Spring boot + hibernate via reverse engineering or is reverse engineering bad?

At my company, we're currently rebuilding our core application, and we're considering going with Spring Boot as opposed to just Java-Web, JAX-RS, and Weblogic.
We also built a database lib using hibernate which we use on a lot of our services, but we want to rebuild that too using Spring boot.
Now, what I desperately need is some sort of reverse engineering tool to help with this spring boot + hibernate migration. I know a question like this has been asked: questions on spring boot + hibernate and the answer given was, use a generic DAO.
But I'm working with more than a hundred tables!
Perhaps I'm looking at this the wrong way. Maybe I don't need reverse engineering to handle this massive work. In which case, I need some advice.
Thanks guys!
I already had the same experience. you can managed to generated a reverse engineered annotation based version of your database using hibernate-tools.
to use hibernate-tools you need to find the stable version of the hibernate plugin at http://www.jboss.org/tools/download. find more instruction at:
How to install Hibernate Tools in Eclipse?
Hibernate Tools in Spring Tool Suite 3.6.1
for further information and instruction on how to get to your aim, I propose you to have look at the following links:
http://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
How to generate domain objects with annotations using hibernate tools
https://www.youtube.com/watch?v=IU7cwWMDdjU
Notice that once you manage to do a reverse engineering against your DB, hibernate-tools does not offer a configuration with spring boot and you need to provide it in you project.

Java Dependency Injection framework with Convention over Configuration feature

In this blog post Mark Seemann explains the different approaches to configure dependencies with a dependency injection framework. Convention over Configuration is one of this approaches. In the .NET world there are multiple DI frameworks which offers this feature (e.g. NInject, MEF 2). I'm searching for a DI framework with Convention over Configuration in the Java world. I looked at Spring and Guice but neither of them seems to offer this feature.
I would argue that hk2 has a convention over configuration like feature with automatic service population. It requires that you use the hk2-inhabitant-generator at build time to put some metadata into your built jar files. However, after that it becomes very simple to populate hk2 with your services. This is how GlassFish uses DI, where classloading at the start of the server had to be kept to a minimum in order to increase boot performance.
There's one for JavaFX by using afterburner.fx is JavaFX MVP framework based on Convention over Configuration and Dependency Injection.

Basic Spring 3 configuration for IOC

Can anybody tell me a basic configuration to use String dependency injection? What are the minimum required jars?
At the moment I'd like to use only Inversion Of Controll, maybe later I'll integrate ORM.
Thanks
Try Spring roo, there is nothing simpler than that to get a full fledged Spring based web application working, with all the dependencies wired together.
Spring STS (an Eclipse distribution customized for Spring available for free from SpringSource) contains several Spring project wizards that produce IoC enabled projects that you could use as examples.
Almost all Spring examples use Maven to define dependencies and download jars automatically from repositories available on the internet.

Integrating grails into an existing spring application?

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.

Categories

Resources