In this article, we provide a series of configuration tips to make it easier for you to complete your daily work using the Spring MVC framework. This topic of configuration management is often overlooked by academia, but this is especially important for real-world web development. We will provide a series of solutions for projects based on this technology based on the Spring MVC framework.
Spring configuration
People often configure a Web application on more than one host. For example, in production, a website may have only one instance. In addition to this instance, developers can configure other (development) instances on the machine used for development. You can also maintain other application devices on the local development server within the company (institution), which will benefit you a lot. The purpose of this example is to enable web designers to obtain quality-assured materials and provide access for those who need to provide documentation for applications.
Everyone knows that even the simplest scenario requires three instances of installation, configuration, and maintenance. For teams located in different geographical locations, it is more difficult to engage in such projects. For any Web application project that is not particularly simple, multiple developers are required to install the project device and local settings, and the device that runs the unit test.
Many organizations use their products as Web applications. We can find this in many products, such as e-commerce systems, content management systems (CMS), and blog publishing platforms. Such products can be deployed on multiple servers. For successful multi-purpose web applications, their developers must ensure that their applications are easy to install and can integrate perfectly with other web applications. After the above discussion, we should understand that the application configuration that is the subject of this article is one of the important problems that developers of general-purpose Web application projects need to solve.
Version control systems such as CVS or Subversion are a standard tool used by development organizations. This tool represents a central source code repository for some organizations, and they are used to keep the source code in order. Users can track changes in application source code, show the differences between different versions, and can determine project branches. Moreover, they make partial updates possible during application deployment.
Obviously, version control system software is necessary to track the source code, and it is very helpful for solving application configuration problems. In this article, we will not focus on the version control system, because there are already many related materials in this regard. Here, we will focus on a small topic in the version control problem: how to make the configuration of Web applications more convenient (especially Web applications written using the Spring MVC framework).
The question is: what kind of configuration are we discussing here? Any web application requires some resources, which are usually unique to the server it runs on, such as a database URL, an SMTP server that sends e-mail, and a folder containing dedicated software files. Such settings should be centralized to make application configuration easier.
However, this is just the simplest version of this problem. Sometimes, more complex configuration is required in application development. This means that different beans in each deployment must be connected, and this makes the problem more complicated.
The solutions to these application configuration problems have many advantages, including: simplifying the installation and configuration of applications, making source code version control easier, and reducing conflicts in the source code repository. Below, we will discuss this topic in detail through examples.
problem
Let's first demonstrate the simplest version mentioned above. In this scenario, we want to change simple configuration parameters, such as link, password, etc., in the application deployment. If you have used the Spring MVC framework to develop web applications, then you should know the two configuration files that will be used here:
So where is the problem? The problem is that applicaTIonContext.xml will include some host-specific bean definitions. Among them, the most obvious example is a bean that contains JDBC connection information, but any slightly more complex application has more than a dozen similar beans. Consider the following example:
The problem with this solution is the maintenance of the applicaTIonContext.xml file. For starters, imagine that the project is placed in a source code version control system, such as CVS. Next, suppose you want to add new functions to the website, then you need to add additional Bean definitions in the application context definition. The question is how to reflect these changes on the production server.
Typically, the local instance of the application will not use the same database as the active site, so the applicaTIonContext.xml file will include settings that allow you to access the local database. When you want to commit changes in the source code repository, you need to pay attention to the synchronization of these host-specific attributes. The files in the repository may eventually use the configuration in the local settings. If you want to update the configuration on the production server, you must manually synchronize the values ​​of these attributes. This is a very boring task, and it is also very error-prone.
This problem is more important for every instance of the application. Suppose three developers are using the base address of the code segment, and they are using a local database. When you commit changes, each of them must be very careful when updating the source code on the local server. They will manually synchronize these changes and then submit their work. As a result, the version control system is useless for these configuration files. If you have used Spring MVC before, you should know that applicationContext.xml is a key component in an application because it glues everything together. Therefore, we need a mechanism to help keep the order in the application, which is very important.
As mentioned earlier, this is a simpler configuration problem you may encounter. The more difficult problem arises when different Bean connections need to be made in different servers. Such problems often occur in daily software development tasks. For example, if your product has a customer authentication module, you can authenticate users from relational databases or LDAP servers. Naturally, this authentication module can be configured using beans that abstract a specific version of the library. If you want to change the way to authenticate users in different application deployments, you need to make different Bean connections in the applicationContext.xml file. This configuration problem is common in all applications that have configurable features in deployment.
In the following, we will discuss these two configuration issues. First of all, we will focus on the problem of synchronous Bean attributes and their solutions. Next, we will discuss the more complicated problem of synchronous Bean connection.
solution
Synchronize bean properties
A feasible solution to this problem is to put all the host-specific parameters into a common Java properties file, and use Spring's PropertyPlaceHolderConfigurer class to write these parameters into the Bean properties.
Using this solution, we can generate the following properties file (/WEB-INF/jdbc.properties):
jdbc.driver = org.postgresql.Driver
jdbc.url = jdbc: postgresql: // localhost / test
jdbc.user = postgres
jdbc.password =
Our Bean configuration is as follows:
As mentioned above, we defined an instance of the PropertyPlaceholderConfigurer class and set its location property to our property file. This class is implemented as a post-processor of the Bean factory and will replace all placeholders ($ {...} value) with the attributes defined in the file.
Using this technique, we can remove all host-specific configuration properties from applicationContext.xml. In this way, we can freely add new beans to the file without worrying about the synchronization of host-specific properties. This can simplify production deployment and maintenance.
Win 3 Unit Cap Lamp Charger CH01 is a smart charger that specially designed for Win3 Cap Lamps.
With Termoelectrical Protection System, and overcharging monitoring, it is Compatible with all our Win 3 Cap Lamps.
It can be mounted to the wall or the place convenient
Easy Manteinance and spare parts replacement.
Compatible with all our win3 cap lamps.
Wall Mount Qi Charger,Wall Mount Phone Charger,Wall Mounted Wireless Charger,Wall Mounted Wireless Phone Charger
ZHEJIANG HUACAI OPTIC-TECHNOLOGY CO LTD , https://www.win3safety.com