Thoughts on building SSH and solutions to several problems encountered

Time:2021-10-9

SSH has been popular for a long time. I’ve seen official documents and online talk about how to integrate SSH and discuss the advantages and disadvantages of various integrations. Today, I’m relatively free and try to integrate these three most popular frameworks with some of my ideas.

The version used this time is struts   1.3.9     Spring   two point five     Hiberante   three point two
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, presentation layer, logic layer and persistence layer   Flower’s guiding ideology is that the less coupling, the better. The lower layer provides services for the upper layer, which is also one of the guiding ideology of rod’s development of spring, so my first thought is how to reduce the minimum coupling.
According to spring   As recommended in the 2.0 official documents, spring integrates with struts 1. X, using both proxy classes and actionsupport. However, I think these two methods undoubtedly have strong invasiveness and dependency, which is somewhat contradictory to the idea of spring.
I use autowireringrequestprocessor. This class will automatically load the service you need for you according to its Java   The doc prompt is bytype matching by default. Of course, you can also use byname. I think it’s OK to use type. Let’s take a look at the two configuration files. First, 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//EN” “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  
It can be found in this file that it is not the same as when it is not integrated with spring. There is 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 superfluous content in it, and there will be no problem of configuring multiple XML files at the same time in the proxy mode, which reduces the amount of maintenance.
At the same time, you will find that I don’t put the specific configuration of Hibernate here, but manage it with hibernate’s own configuration.

In this way, the dependency between our three layers will be reduced to a low level, and both ends can be changed to one of them at will.

By the way, it is often found in common books that there is no such in-depth discussion. Are you afraid that beginners can’t understand it?
In addition, for an architecture, the problems to be solved do not mean these. Generally, we can consider all aspects of the architecture by using the 4 + 1 view of RUP. We can also break through the following aspects: security, data input and output verification and conversion, internationalization, log, exception handling, heterogeneous system integration, background running programs, etc. If there are multiple databases, we need to think more about transaction control.

I think I will improve this integration later and implement a demo as the basis for the rapid development of small and simple projects.

The following problems have been encountered during integration:
Problem 1: error during startup   “Severe:   Error   listenerStart  ”
There are many online solutions to this problem:
One of the simplest solutions is to initialize spring with listener instead of servlet, but this method is not very good. First, the root cause is not found, and second, it may bring new problems.
A better solution is to add the relevant configuration of log4j, and then start it again. Various details will appear, which can be solved according to the specific information. Generally, there may be a problem with the datasource configuration or environment configuration.
Reference website: http://hi.baidu.com/xht314/blog/item/808ecf13c1dd1820dd5401af.html

Question 2: encountered “required”   extension   qdox   not   “Found”
There are also answers on the Internet. My method is to directly remove the package commons-attributes-compiler.jar. 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: the conflict between struts package and spring package
When I encounter package conflicts, it’s OK to change the priority required by struts. Now the jar files are getting more and more troublesome. The jar files of many projects are messed up by developers. It seems that Maven is a good thing, at least the idea is good, and it may need to be studied in the next step.

Recommended Today

[hematemesis finishing] Super complete golang interview questions collection + golang Learning Guide + golang knowledge map + growth route

The brain map is constantly updated. Check the address onlineSubsequent articles and contents will be updated toGitHub projectWelcome to pay attention. Directory (Ctrl + F) Basic introduction Novice 50 mistakes that golang novices often make data type I don’t even know that nil slice is different from empty slice? Then the bat interviewer has to […]