I'm kinda stuck on this decision. My project already uses Spring and Spring Blazeds integration but I don't think there will be any real web interface (HTML). I have limited experience with Spring MVC and the Spring validators which are OK, but I've read comments from people suggesting not to use Spring validators outside Spring MVC.
What validation framework would you recommend based on personal experience?
"..., but I've read comments from people suggesting not to use Spring validators outside Spring MVC..."
I'd like to see those citations. I've used the Spring DataBinding API outside Spring MVC, and it's terrific. I would say that criticism is unfounded.
Apache Commons Validator is an alternative, but I'd still recommend Spring's DataBinder first. Especially if you're already using Spring. The benefit of switching to anything else is more than offset by the cost of yet another dependency.
You can try Hibernate Validator which is in fact the reference implementation for JSR 303: Bean Validation. BTW, it is still in beta.
Related
I'm new to Spring.
The goal is to learn Spring, to use Spring as a production application as it is industry standard.
The requirements of the app:
Hibernate, Security, MVC, RESTful, DI, etc.
The other Spring frameworks might be added in future.
I'm reading "Spring in Action. Third Edition." by Craig Walls.
He gave the examples how to use annotations, but anyway .xml is used.
I'm wonder if I can write the application using only java classes to configure all modules in the application.
I found Spring Boot gives ability to develop not using xml files. However I read the article http://steveperkins.com/use-spring-boot-next-project/ and author said Boot is not ready to be used for production applications.
As far as I understood Boot hides all config work from me. Also my concern is that in future java-developers who knows Spring won't be able to deal with Spring Boot and I wouldn't find proper engineers for the project.
Based upon this I have the following questions:
Is it possible to avoid using xml in Spring or better to mix xml files and annotations?
Is it easy for Spring developers to work with Spring Boot?
Am I able to learn Spring using Spring Boot?
Is Spring Boot is mature enough to use it in production?
Is it possible to avoid using xml in Spring or better to mix xml files and annotations?
Yes, it is. Spring now promotes Java configuration, and it's perfectly doable (I'm doing it) and even easy to only use Java to configure your Spring app. Even without using Boot.
Is it east for Spring developers to work with Spring Boot?
Why wouldn't it? It's well documented, and is based on Spring best practices.
Am I able to learn Spring using Spring Boot?
How could I answer that. Try doing it, and you'll see if you're able or not.
Is Spring Boot is mature enough to use it in production?
Yes, it is. The articleyou linked to is one year old. Spring developers have worked a lot on Boot since then. And Spring uses Boot internally to host their own spring.io web application. See https://github.com/spring-io/sagan
JB Nizet answered 3 answers very clearly. Just an addition about production readiness from my side. We are currently using Spring Boot for an application which we intend to move to production. There has not been any issue till now in prototyping and testing phase. It is very convenient and avoids boilerplate and gives production ready, standalone jar file with embedded server. You can also chose to build war file if you prefer.
"Am I able to learn Spring using Spring Boot?"
As you mentioned that you are new to Spring, it would probably be easier for you to pick up Spring Boot quickly.
To get started, if you are interested, following is the link to a webinar by Josh Long which gives you a really good insight of how easy it is to pick up Spring Boot:
https://www.youtube.com/watch?v=eCos5VTtZoI
I don't know much about Spring Boot but I know pretty much about spring.
First of all you can use both annotations and xml configuration file/s in the same project. That is the most common way as far as I know.
There is also JavaConfig configuration option in which you don't use any xml files instead you use ordinary java class with #Configuration annotation. I didn't use and not saw much usage also.
You can make a spring webapp without any xml, although spring security was ugly to configure last time I looked at that. For a webapp you need to implement WebApplicationInitializer, create an application context and register your #Configuration file(s) with the context. Then you register the dispatcher servlet and you're all set!
I was nearly in the same boat four months ago when I started working on my web app & chose Spring as the platform after evaluating many choices. I also started with Spring in Action but got frustrated when the examples provided by the author didn't work (Spring basic MVC app not working). Since I was just starting, I was looking for some very basic but working examples. But unfortunately, most of the examples which came along with Spring text books, didn't work straight out of the box.
I would like to suggest few Spring resources which I found useful for starters:
http://springbyexample.org/
http://www.petrikainulainen.net/tutorials/
http://www.mkyong.com/tutorials/spring-tutorials/
Pro Spring 4th Edition
Spring Documentation (must read, but take your time to understand the concepts)
Now, to answer your questions, although a bit differently:
Is it possible to avoid using xml in Spring or better to mix xml files and annotations
Now a days, you would find Annotations a lot in Spring code available on net/SO along with XML configuration. However, you can certainly avoid XML if you wish.
Is it easy for Spring developers to work with Spring Boot?
Am I able to learn Spring using Spring Boot?
Is Spring Boot is mature enough to use it in production?
My personal opinion would be to go with Spring Boot only if you believe it offers you certain advantages which are not possible to achieve otherwise. Remember, you may save time now but later on, it would be an additional dependency in your app and you may need to understand its architecture to debug it if things go wrong OR to enhance it as per your app requirements. Better to have minimal dependencies, my learning till now :)
This question already has answers here:
What are Dependency Injection & Spring Framework about? [duplicate]
(10 answers)
Closed 9 years ago.
I keep seeing the phrase Dependency Injection whenever I search for Spring Framework in Google.
In plane English , can someone please explain what exactly is Spring , and why would I want
to use it ?
For example , a few days ago I've learned about Hibernate : it converts JAVA objects into records
in a DB table ... it's great , reduces the amount of code and a bunch of SQL statements .
So, how exactly does Spring helps me?
Spring is a framework which supports (among other things) dependency injection. Using Spring also makes it very easy to create web applications. Spring favors convention over configuration and was originally created as an alternative to Java EE (which was overly complex, verbose, and burdensome). But Spring is more than just dependency injection. It has core support for dependency injection, transaction management, web applications, data access, messaging, aspect-oriented programming, testing, and more.
Spring helps you by making it easy to inject dependencies, which reduces tight coupling between a class and specific implementations. For web applications, Spring follows the MVC (Model View Controller) pattern, and has specific annotations (and XML-based configuration) to help you write code that follows this pattern.
I suggest reading more about dependency injection, MVC, and the Spring framework in general to know more; there's far too much information to cover in just a single answer.
It creates loose coupling between elements due to DI. Best explanation as always by Martin Fowler
Recommended reading:
Spring in action
Official documentation
Plainer than "dependency injection"?
Let's ask what it is and why you'd use it. This is still the best explanation I know of.
Spring is more than dependency injection. It's a three legged stool:
dependency injection
aspect-oriented programming
libraries for web MVC, database, messaging, remoting, and more
There are other DI engines out there, like Guice.
If you have to ask, I'd suggest that you dig into it more before deciding.
I have read that the main uses of spring is DI and AOP.
As far as i understand spring in 3 weeks , i feel that AOP can be done in aspectj
and DI is technique not specific to spring with API's.
so is i am missing anything. spring only creates beans.
is that it
I have read that the main uses of
spring is DI and AOP.
And the modules and libraries that come with both. Spring is a three-legged stool, in my opinion.
As far as i understand spring in 3
weeks , i feel that AOP can be done in
aspectj
Of course AOP can be done with AspectJ - as long as you don't mind byte code alterations. You can also use Spring's original AOP, which uses proxies and is less invasive.
and DI is technique not
specific to spring with API's.
I'm not sure I understand your point here. The wording isn't very clear. If your point is that DI can be done without Spring, then I'd say you are correct.
so is i am missing anything. spring
only creates beans.
I'd say you're missing everything.
is that it
What else do you want it to do?
What alternative do you prefer?
UPDATE:
I don't know about PHP, but there's a version of Spring for Python: Spring.py. This suggests to me that you can certainly do both DI and AOP in Python. I would say that they're possible in any language that's truly object-oriented. The ideas of DI and AOP are like any other OO pattern: language agnostic.
It is a container and MVC web application framework as well. There is also OSGI support. Spring consists of many parts/modules, which can be integrated with other frameworks such as Hibernate.
http://www.springsource.org/about
Spring is in my opinion a defacto standard when it comes to developing web applications/services, or even general application development.
It provides dependency injection as one of its strongpoints, to offer the conveniance of having all necessary tools in one package.
AoP on the other hand nicely integrates with Spring, but is in no way a fundamental reason to use spring. In fact, I dare to claim that alot of people probably don't explicitly (the underlying framework might still do it for you though). You can probably use spring a lifetime without having to explicitly use AoP.
Can I use Struts2 without Spring IoC?
Spring is only one option. You can work with others like Google Guice or without IOC.
Yes you can, even when you can integrate both on your project, it is not required.
Struts2 was designed with dependency injection in mind and adheres to the principles pretty well (the underlying XWork framework uses an early version of Guice). You can step up to Guice or Spring later using the appropriate plug-in.
Yes
Spring IOC is just a pluggable object dependency container, which manages objects for you. It is optional.
Basically both are independent. You can definitely use Struts 2 without Spring IOC.
I am new to Spring and now a days I hear a lot about Spring Framework. I have two sets of very specific questions:
Set No. 1:
What are annotations in general ?
How does annotations works
specifically with Spring framework ?
Can annotations be used outside
Spring Framework or are they
Framework specific ?
Set No. 2:
What module of Spring Framework is
widely used in Industry ?
I think it is Spring MVC but why it
is the most used module, if am
correct or correct me on this ?
I am newbie to Spring and so feel free to edit this questions to make more sense.
What are annotations in general?
Annotations can be thought of as meta-data for classes.
How does annotations works
specifically with Spring framework?
Spring uses annotations as an alternative to XML for declarative configuration. Some people don't like XML.
Can annotations be used outside Spring
Framework or are they Framework
specific?
You need the implementation JARs to use any annotation, so if you use the annotations you are using Spring. Annotations are a general idea introduced into Java 5. You can write your own as well.
What module of Spring Framework is
widely used in Industry?
Spring Core is used by all the other modules; hence the name.
I think it is Spring MVC but why it is
the most used module, if am correct or
correct me on this ?
Absolutely incorrect. Spring MVC has lots of competitors (e.g., Struts 1 and 2, JSF, Wicket, Flex, etc.), so it's not always the first choice for web MVC. And all apps that use Spring aren't web apps. Spring Batch and Integration are quite popular and growing.
Annotations were introduced in Java 5 http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html and are not Spring specific. In general, annotations allow you to add metadata to a class, method or variable. An annotation can be interpreted by the compiler (for example, the #Override annotation) or by a framework such as spring (for example, the #Component annotation).
Spring has many different annotations, so you would need to be more specific about which annotations you have questions about. But Spring annotations can only be used within Spring, and other annotations can be used within other frameworks.
For Set No 2 of questions, that should be opened as a second questions since it doesn't relate to the annotations.
Annotations in Java programing language is a special form of metadata that can be embedded in Java source code. The use of annotations in Java language is introduced in Java 5.0 ie Java 5 provides metdata support at language level.
In Spring, XML based configurations is the most popular configuration style.. Then annotation based configuration style came which enables users to configure beans inside the java source file itself. Spring framework provides different custom java5+ annotations. These annotations can be used in transactional demarcation, aop, JMX etc. There are core Spring Annotations, Spring MVC Annotations, AspectJ Annotations, JSR-250 Annotations, Testing Annotations etc. Both xml based configurations and Annotations have pros and cons. I would suggest mixing the two.
The custom Spring annotations are framework specific. But you can write your own annotations also.
The Core container module is the most important module which handles the basic principle of Dependency Injection and it's used in all other modules in the framework. Spring MVC is only a web MVC framework built on Spring's core functionality.
You can go through Spring documentation and books like Spring in Action and Spring Recipes to get a good idea about the framework.
What are annotations in general ?
Annotations are a convienient way of configuration, which could also be done using explicit configuration files, like deployment descriptors.
How does annotations works
specifically with Spring framework ?
In spring they are used for dependency injection and many other purposes
Can annotations be used outside Spring
Framework or are they Framework
specific ?
Yes you can even write your own annotations. They have been introduced in java 1.5 for i.g. suppresing warnings.
What module of Spring Framework is
widely used in Industry ?
The spring core module is used in all applications and therefore mostly used.
You should also browse the Documentation to get a first impression what the spring framework and its modules cover.