Thoughts on how to build SSH and solutions to several problems

Source: Internet
Author: User
Tags one more line

SSH has been popular for a long time. I have been reading official documents and talking about how to integrate SSH and discuss the advantages and disadvantages of various integrations. Today, I am idle and try to integrate these three most popular frameworks with some of my ideas.

This version is Struts 1.3.9 Spring 2.5 Hiberante 3.2.
Development tools and environment: Eclipse 3.3 + MyEclipse 6.0 + JBoss 4.2 + Tomcat

When using SSH, our architecture will naturally be divided into three layers, namely the presentation layer, the logic layer and the persistent layer. According to Martin Flower's guiding ideology, the less coupling, the better, the lower layer provides services for the upper layer, which is also one of Rod's guiding ideology for Spring development. So the first thing I think of is how to minimize coupling.
According to the practices recommended in Spring 2.0 official documents, Spring is integrated with Struts1.x, which adopts the proxy class and ActionSupport, however, I think these two methods are undoubtedly highly invasive and dependent, which is in conflict with the idea of Spring.
I use AutowiringRequestProcessor. This class will automatically load the Service you need. According to the prompt of Java Doc, the default value is byType matching. Of course, you can also use byName, I think it's okay to use the Type method. Let's take a look at two configuration files, let's take a look at the Struts configuration file struts-config.xml:

1 <? Xml version = "1.0" encoding = "UTF-8"?>
2 <! DOCTYPE struts-config PUBLIC "-// Apache Software Foundation // DTD Struts Configuration 1.3 //" http://struts.apache.org/dtds/struts-config_1_3.dtd ">
3
4 <struts-config>
5 <form-beans>
6 <form-bean name = "loginForm" type = "com. ***. ssh. view. login. LoginForm"/>
7 </form-beans>
8
9 <global-exceptions/>
10 <global-forwards/>
11 <action-mappings>
12 <action name = "loginForm" path = "/login" scope = "request"
13 type = "com. ***. ssh. view. login. LoginAction" validate = "false"/>
14 </action-mappings>
15
16 <controller
17 processorClass = "org. springframework. web. struts. AutowiringRequestProcessor"/>
18
19 <message-resources parameter = "ApplicationResources"/>
20 </struts-config>
21
22
In this file, we can find that it is a little different from when it is not integrated with Spring, with one more line:
<Controller processorClass = "org. springframework. web. struts. AutowiringRequestProcessor"/>

Let's take a look at the Spring configuration file applicationContext. xml:

1 <? Xml version = "1.0" encoding = "UTF-8"?>
2 <! DOCTYPE beans PUBLIC "-// SPRING // dtd bean // EN" "http://www.springframework.org/dtd/spring-beans.dtd">
3
4 <beans>
5
6 <bean id = "SSHSessionFactory"
7 class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean">
8 <property name = "configLocation">
9 <value> classpath: hibernate. cfg. xml </value>
10 </property>
11 </bean>
12
13 <bean name = "LoginService"
14 class = "com. ***. ssh. biz. login. LoginService" singleton = "false">
15 <property name = "dao">
16 <ref bean = "UsersDao"/>
17 </property>
18 </bean>
19
20 <bean id = "UsersDao" class = "com. ***. ssh. persistence. UserDao">
21 <property name = "sessionFactory">
22 <ref bean = "SSHSessionFactory"/>
23 </property>
24 </bean>
25 </beans>
26
There is no extra content here, and there will be no problem of simultaneous configuration of multiple XML copies in the proxy mode, which reduces the maintenance workload.
At the same time, you will find that I did not put the specific configuration of Hibernate here, but managed by Hibernate's own configuration.

In this way, the dependency between the three layers will be reduced to a lower level, and the two ends can be changed to a certain layer.

By the way, the common books often do not have such in-depth discussions. Are you afraid that beginners will not understand them?
In addition, for an architecture, the problems to be solved do not refer to these. Generally, we can consider all aspects of the architecture using the 4 + 1 View of RUP. We can also break through the following aspects: security, data input and output validation and conversion, internationalization, LOG, exception handling, heterogeneous system integration, and background running programs. For multiple databases, we need to consider more transaction control.

I think I will improve this integration and implement a Demo later, which serves as the basis for quick development of small and simple projects.



Integration encountered the following problems:
Problem 1: "severe: Error listenerStart" occurs during startup"
There are many solutions to this problem on the Internet:
One of the simplest solutions is to use Listener to initialize Spring with Servlet, but this method is not good. First, the root cause is not found, second, there may be new problems.
A better solution is to add the related Log4J configuration and then start the Log4J with various details. This can be solved based on the specific information, which may be DataSource configuration, or the environment configuration is incorrect.
Reference: http://hi.baidu.com/xht314/blog/item/808ecf13c1dd1820dd5401af.html

Question 2: a prompt like "Required extension qdox not found" is displayed.
There are also answers online, I use the method is to directly remove the commons-attributes-compiler.jar package. Of course, if you want to use this package, you can refer to the following address:
Http://hi.baidu.com/sky_lei/blog/item/77ee17085543b232e8248824.html

Question 3: Conflicts between Struts and Spring packages
I encountered a Packet Conflict and changed it to Struts. Now the JAR file is getting more and more troublesome. Many project JAR files are messy by developers, it seems that Maven is a good thing. At least the idea is good. You may need to study it next.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.