Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Spring inject a type of object to enumerate     - Installation and operation GAMIT software under Linux operating system (Linux)

- Java generate two-dimensional code by Zxing (Programming)

- Boot automatically remove Linux operating history records (Linux)

- Distributed transaction management Spring declarative transactions (Programming)

- Oracle 11g partition maintenance (two) - Coalescing Partitions (Database)

- CentOS install Java 1.8 (Linux)

- Linux Getting Started Tutorial: How to set up a static MAC address on VMware ESXi virtual machine (Mobile)

- The PostgreSQL database pg_dump command line does not enter a password method (Database)

- Installation of Python2.7.8 and iPython under CentOS6.5 (Linux)

- Linux Getting Started tutorial: build your own Vim (Linux)

- Git build a team development environment operating drills (Linux)

- Linux Command study manual - GPG command (Linux)

- Puppet 3.x installed on Debian 7 (Server)

- RedHat 6 xrdp use remote login interface (Linux)

- Ubuntu 15.04 installed Nvidia Quadro series graphics driver (Linux)

- Upgrading Oracle to (Database)

- 64-bit Oracle Linux recompiled Hadoop-2.2.0 (Server)

- RabbitMQ installation, configuration, monitoring (Linux)

- Oracle and MySQL difference between the jdbc (Database)

- Oracle 11g partition maintenance (Nice) - Truncating And Partitions (Database)

  Spring inject a type of object to enumerate
  Add Date : 2018-11-21      
  1, The enumerator

In actual programming, often there is such a "data set", and their value in the program is stable, and that "data set" of elements is limited.

For example, Monday to Sunday seven data elements for a week "data set" data elements four seasons four seasons of "data set."

In java how to make better use of these "data sets" mean? So he sent the enumeration handy, it is an example of enumeration:

public enum ColorEnum {
2, in the spring configured inject an enumerated type of object

1), the definition of an enumeration type object

package com.zcr.util;
public enum ColorEnum {
2) Use enumerated type classes have

package com.zcr.util

// Enum type
public class Car {
    private ColorEnum colorEnum;
3), spring configuration file by adding the following code

// Spring injection profile



To enumerate types injected into the class, be sure to use org.springframework.beans.factory.config.FieldRetrievingFactoryBean class enumeration type conversion, namely


RED ColorEnum.RED will convert this bean, then used to inject the bean can be referenced.

3), the call

You want to inject in places like add the following code to the class information injection.

private Car car;
3, the use of java comes with a Enum (enum) type of injection tests

there are also a lot of java enum class, such as java.util.concurrent.TimeUnit, its class is defined as follows:

public enum TimeUnitextends Enum
From the above definition we can see that it is an enumeration class. Now I want to configure it to generate an instance file by spring.

In the spring configuration file if the following configuration:

Class call:

private TimeUnit timeUnit;
Thus the object is to get the child.

4. Why do you want to use the file to configure the way?

The TimeUnit want java class, it has a variety of units of time, in milliseconds, seconds, minutes, hours, days ......, and when we're using in the project, must be unified unit of time, so we can profile configuration, so sub favor decoupling and when we want to modify the unit of time, we simply modify our profile on it, (or less preferably change the code). At the same time, we affirmed in many places uses TimeUnit this object, if we configured in the configuration file, you only need to modify a position to complete all modifications call, easy to modify the project.
- Ubuntu and derived versions of the user how to install G Mic (Linux)
- CentOS6 5 Configure SSH password Free (Linux)
- High-performance JavaScript loaded and executed (Programming)
- Axel install plug under CentOS 5/6 acceleration yum downloads (Linux)
- Linux shell in back quotes (`) Application (Linux)
- The principle Httpclient4.4 (execution request) (Programming)
- With screenfetch linux logo and basic hardware information display with cool Linux logo (Linux)
- The method to mount the CD under Linux (Linux)
- Some safety precautions of Linux servers (Linux)
- SteamOS installation under Ubuntu 14.04 (Linux)
- Ubuntu Backup and Recovery (Linux)
- grep regular expression (Linux)
- Java Foundation - Getting Start (Programming)
- MySQL5.7 JSON type using presentation (Database)
- Using Maven to download Spring (Linux)
- Restrict console access to Linux servers to improve security (Linux)
- Ubuntu Tutorial - Manually install Oracle Java JDK 8 (Linux)
- CentOS7 management of systemd (Linux)
- Cygwin install Python MySQLdb (Linux)
- Oracle 12C RAC optimizer_adaptive_features cause of data into overtime (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.