XML-less configuration for struts1 - struts-1

A very bad news: I have to use struts 1.x in my projects.
There are so many XML configuration for struts1, which is so boring. Is there any way to avoid them? For example, struts plugins, annotations, or others ?

Not within the Struts project itself.
There's Struts Annotations, which I've not used.
In the olden days, XDoclet's Struts tags was the norm for XML-less config.
If neither of those strike your fancy, simply generating an XML config programmatically via a DSL or builder patter works.

Related

Spring Security - XML vs Java Configuration

I'm just learning Spring Security, and a lot of Spring's documentation appears to use Java-based bean configuration (as opposed to XML.) Overall, this seems to be the way a lot of their projects are going. However, portions of their documentation tend to start with Java configuration and then switch to XML config later on. I found a blurb in one document (http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/) stating the following:
Spring Security’s Java Configuration does not expose every property of every object that it configures. This simplifies the configuration for a majority of users. . . . While there are good reasons to not directly expose every property, users may still need more advanced configuration options. To address this Spring Security introduces the concept of an ObjectPostProcessor which can used to modify or replace many of the Object instances created by the Java Configuration.
Can everything that can be done in XML configuration be done with Java config? Is there a definite direction that the Spring community is taking overall in terms of configuration style?
You can choose either java based or xml based configuration.Stick to one, don't mix both.But don't forget to use the annotation based configuration.You just need to annotate spring managed components with #component,#service etc.You don't need to have that bean defenition in xml or java class.
<context:annotation-config/>
<context:component-scan base-package="com.package"/>
or
#Configuration
#ComponentScan({"com.foo.bar", "org.foo.bar"})
http://docs.spring.io/spring-security/site/docs/3.2.0.RC2/reference/htmlsingle/#jc
You can use Java or XML based. But there is a thing
Usage of xml based configuration is decreasing in newer versions of Spring.
Like #EnableAutoConfiguration tag...
With this, web applications doesnt need any XML conf even web.xml

Spring Annotations when java file is compiled

I started learning spring today and i have a question regarding what happens to the annotations when java files with annotations is compiled ?.
The reason i am asking this is because of the fundamental difference i see when we choose to use the xml approach vs the annotations approach , and what i think is the philosophy of spring. The way i understand is spring says that all your java classes can be simple pojo's and all the spring related config should be kept independent (Like xml file.)
In case of developing spring application using xml *.java files have no idea about spring container and are compiled in to .class without any spring related dependencies.
But now when we annotate the .java file and the file is compiled the compiled file now has all spring related dependencies hard baked in to it and no longer are your classes simple pojo's.
Is this correct ? I am not sure if i am missing some thing here.
Annotations can be considered as metadata of a class or its element (method, field, local variable...). When you put annotation, you don't implement any behaviour. You just give additional info on an element.
That way, Spring, which is in charge of instanciating its bean can collect the info with reflection (see also this site) and process it.
To conclude, your Spring beans still remain POJO and there is no difference with the XML way (...from that point of view) since Spring gets from annotations the information it would have got from XML .
I think you are right and your question is justifiable, that's the way how I think about it too.
Not only compiled code but also dependency on spring jars bother me. Once you use this annotations your resulting jar depends on spring library.
It's reasonable to store beans in model according to DDD but spring is some kind of infrastructure layer so I didn't like the dependency.
Even if you would use XML, it's useful for few placed to use attributes. E.g. #Required attribute which is useful to verify that linked bean was injected. So, I've decide to use constructor dependency injection to omit this attribute, see my article. I completely leave out the dependency on spring in the code.
You can probably find such mind hook for many annotation you want/force to use.
You can use annotations only for your configuration classes, without marking them actual bean classes. In such scenario if you not use spring you just not load configuration classes.

Meaning of tag of struts.xml file of a Java EE projects using struts 2 spring 3 and hibernate

I'm trying to make a project using struts 2, spring 3 and hibernate, but when I come to the step to write the struts.xml, I couldn't find a site which gave an explanation about the tag (and their attributes too) used in this file (tag such as package, action, result etc).
So is there any tutorial or refcard that gives an explanation about them?
What is the role that has in a Java EE project?
There are complete information about the various tags/attributes there layout in the xml DTD file. If you will use any IDE for the development it tend to give complete information about the elements and allowed attributes as well there positions.
Here are the links for some of documents for details
The Struts 2 Document Type Definition (DTD).
configuration-elements in struts.xml
Hope this will help you

Migrate struts action to spring action

I am looking for a good tutorial on migrating from struts to spring. I have multiple struts actions that I would like to refactor into spring components.
Here's one (assuming you're talking about Struts 1, although you don't specify).
Not sure how helpful it will be; depending on how clean the original Struts code was it could be relatively straight-forward, or brutal.
In my experience the bulk of the work lies in the JSPs, not the actions themselves, particularly if the S1 code made extensive use of the Struts tags. The actions themselves are easier to deal with because of strong IDE support.

Validate Spring XML schemas against XSDs from classpath

Can anyone tell me what the best strategy to validate a spring configuration file against the spring-beans.xsd that is included with the spring-beans.jar. Can I have the schemaLocation in the XML header reference file:/org/springframework/beans/factory/xml/spring-beans-2.0.xsd?
The best way is to use the Spring IDE and it will perform the validation during dev time. Also, spring auto validates all the config files (from the XSD that comes bundled with the jars) while it is loading them.
ok here is the deal.... Eclipse uses plugins like spring IDE or spring STS that have spring bean validators in them.
There is an issue When the new versions of spring components come out the xsds do not appear to be in the eclipse plugins validators ahead of time. So eventually they create bug or enhancement requests in the projects JIRA system and they are put in in a new release/update. You can vote on these bugs to let them know there is demand to get them in faster.
There is also a work around to use in the interim in this old blog post by Craig Walls
http://www.springone2gx.com/blog/craig_walls/2007/08/fixing_spring_modules_xsd_errors_in_eclipse

Resources