Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Spring inject a type of object to enumerate     - Struts2 form of non-use component tags (Programming)

- How to Install Sticky Notes on Ubuntu and Derivatives (Linux)

- Shell Common Command Summary (Programming)

- Linux Getting Started tutorial: Experience QEMU virtual machine articles (Linux)

- Linux file compression and archiving (Linux)

- After reloading the cinder-volume OpenStack not start properly (Server)

- How Datadog monitor Nginx (Server)

- How to install and use the Snort in Ubuntu 15.04 (Linux)

- Linux Variable content removal and replacement (Linux)

- Using 30 seconds to write a detailed analysis of garbage removal system (Linux)

- 6 common PHP security attacks (Linux)

- Linux 10 useful examples of command-line completion (Linux)

- Linux System Administrator common interview questions and answers 30 (Linux)

- Oracle table compression Technology Introduction (Database)

- WordPress plug-ins installed in Ubuntu, enter the subject of FTP and not create directory problem (Server)

- Sniffer Linux Environment (Linux)

- Teach you self-built Linux firewall free (Linux)

- JavaScript in null undefined summary (Linux)

- Install the Red Hat Container Development Kit on OSX (Server)

- ASM Management - How to Rename diskgroup (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 14.04 How to set up an SSH without password (Linux)
- Use preseed script to install Ubuntu 14.04 (Linux)
- Java data structures - the single linked list LinkedList linear table (Programming)
- GitLab issued Merge Request return error 500 when the two solutions log (Linux)
- Two strokes to improve development productivity Struts2 (Programming)
- Installation and use the telnet command under CentOS 6.x (Linux)
- ntop monitoring software configuration and installation (Linux)
- VirtualBox install Windows 8.1 has encountered an error 0x000000C4 solutions (Linux)
- C language to view various types of data size (Programming)
- Camouflage Nginx Web server version to prevent invasion (Linux)
- Raspberry Pi 2 to install the latest version of the FPC and Lazarus 1.5 (Linux)
- Android graphic introduction NDK installation and simple jni demo implementation (Linux)
- Hadoop new and old version of the difference in the size of the InputSplit (Server)
- Memcache explain in detail (Server)
- Use PuTTY key authentication mechanism for remote login Linux (Linux)
- Justniffer installed on Ubuntu 15.04 (Linux)
- LVM basic concepts, management (Linux)
- PXE installation of Linux servers (Server)
- How do I cancel (almost) any operations in Git, (Linux)
- Hackers is how the invasion and control of Things devices? (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.