Can I use Struts2 without Spring IoC? - java

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.

Related

why do we always put Hibernate, Spring and Strut in one app?

Definitely, I'm talking about working with MVC pattern.
Definitely, Hibernate make our life easier with Model layer.
But, Spring and Strut both work with Controller and View.
So, my question is: "I cant understand why other guy always put both Spring & Strut in one application while we need just one of them (Strut or Spring). If anyone understand that, please tell me, thanks!"
I'm just a kid in Java world, so any comments are appreciated.
But, Spring and Strut both work with Controller and View.
Spring is many things, as you can see in this diagram:
One of these things is the Spring MVC framework. I agree, it does not (usually) make sense to use Spring MVC together with Struts (although in large sites, different departments may have different requirements).
However, Spring is also many other things, most of all an IOC framework, and as such it makes perfect sense to integrate different model and view technologies.
Spring is both Spring - the IOC container and Spring MVC - the web action framework. Struts is only a web action framework. So if you prefer Struts over Spring MVC, but also want an IOC container, you will use Struts with Spring.
Additionally, Spring also provides declarative transaction management, a security framework, a set of JDBC helper classes, etc., that you might want to use in a Struts/Hibernate application.
I wouldn't say always. Personally, I have never put Spring and Struts together in the same application, and I am willing to bet that most Spring/Hibernate projects also do not also use Struts.
Spring isn't just MVC. It has much more integrations, such as database, security, DI etc. Usually you want to use one of that features if you use Spring (which doesn't also mean, that you have to use Spring MVC).
Lets say that Spring and Struts are both frameworks that do overlap in some aspects. Even if I think that, if you are utilizing spring to its full extent, there should be no need for struts at all. But people tend to stick with the stuff they are used to. As Struts has been around for quite some time there are a lot of applications based on this and a lot of people that have made a profession out of this and would never commit throwing that away. That's why I have seen quite a lot of these hybrid application around.
I think you misunderstand MVC Pattern in first place. Model is not about persistence, but about the business logic in first place. It usually involves some persistences and service classes. For this purpose, many people choose Hibernate for persistence and Spring IoC for dependency injection purpose.
For the View and Controller part of web application, a well known web mvc framework is Struts and Spring MVC. Spring itself is consists of many components, Spring IoC and Spring MVC is two of them. Spring MVC is an equivalent with Struts so you don't use them together. But it is ok to combine Struts and Spring IoC.
Struts - usually provides MVC framework (most of Production support & maintenance applications are already integrated with it).
Spring - to inject/ add new componenets without disturbing the existing java classes/ code.
IT mostly depends on your project requirement, in our project we have used JQuery there are lots of Struts tags are used at the UI Layer and that is the main reason we are using struts2 because struts2 is having very good integration with JQuery
Struts2-JQuery Tag Library is very useful hence we are using Struts2
+
Spring framework provides an easy way to manage the dependency. (because of its DI and IoC)
It can be easily integrated with struts 2 framework.
The ContextLoaderListener class is used to communicate spring application with struts 2.

uses of spring framework in java

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.

How can use Struts 2.0, Spring and Hibernate in my framework

Is it possible put these three framework Spring, Struts 2.0 and Hibernate in single application and how without using JPA?
Struts2, Spring and Hibernate ARE frameworks, so your question makes little sense. If you mean "can I use Struts2, Spring and Hibernate to build my web application?", the answer is yes, in principle - they play together all right.
Check the official documentation of springsource to know how it works and how to implement them.
Spring Official documentation
Look at Current Releases -> Reference manual, of your version. Everything is explained.
With the information you provide, use the Hibernate JPA implementation and you are done.

What are annotations and how do they actually work for frameworks like Spring?

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.

What java validation library should I use?

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.

Categories