Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Spring inject a type of object to enumerate     - Ubuntu 15.04 installed JDK and configured as the default JDK (Linux)

- To learn from scratch OpenWrt perfect tutorial (Linux)

- IO reference Docker container (Server)

- MySQL in order by inaccurate results in problems and solutions (Database)

- How to fix the Ubuntu Error script returned error exit status 1 (Linux)

- To build a private Docker registry (Server)

- How the program is executed (Programming)

- Shell script to delete empty folders recursively (Linux)

- Two programs HAProxy + Heartbeat (note, the secondary server vip, normal HAProxy boot method) (Server)

- Character Encoding notes: ASCII, Unicode and UTF-8 (Linux)

- Ubuntu 10.10 install Oracle 10g Installation Guide (Database)

- Bash code injection attacks through a special environment variable (Linux)

- APR for Tomcat installation under Linux (Server)

- Asynchronous JavaScript loading (Programming)

- React Getting Started Tutorial (Linux)

- Configuring Proxy on a Unix terminal, accelerate Android Studio Construction (Linux)

- MongoDB Study Notes (1) - Install MongoDB on Windows systems (Database)

- Nginx Load Balancing (standby) + Keepalived (Server)

- CentOS system dual network card IP information configuration (Linux)

- SpringMVC garbage processing (Programming)

  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 Install OpenSSL (Linux)
- I use the desktop environment in GNU / Linux combination tool (Linux)
- Compression software on a simple comparison of zip and gz (Linux)
- Installation Enpass secure password manager on Ubuntu (Linux)
- Shell command line operation (Linux)
- CentOS 7.0 Enable iptables firewall (Linux)
- Compression decompression command under Linux (Linux)
- Python Basics: Search Path (Programming)
- Oracle database physical file backup / restore (Database)
- CentOS 6.5 installation using a data recovery software extundelete (Linux)
- SSH does not require a password to log on to a Linux server (Server)
- Eclipse, Tomcat configuration JNDI connection Oracle data source example (Server)
- To install JDK1.7 and compiler Hadoop-2.7.1 under CentOS7 (Server)
- Linux system ARP attack solution (Linux)
- MySQL function: group_concat () function (Database)
- Red Hat Linux security settings document (Linux)
- How to use Linux to download music from Grooveshark (Linux)
- Linux vi command list (Linux)
- Ubuntu 10.10 install Oracle 10g graphic tutorials (Database)
- Puppet installation and testing (Server)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.