Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Spring inject a type of object to enumerate     - Install the latest ATI / Nvidia graphics driver on Ubuntu (Linux)

- Installation on the way to the root source Ubuntu Server 14.04 LTS version Odoo8.0 (Server)

- Linux start the process (Linux)

- Squid proxy server configuration under Linux (Server)

- Ubuntu 12.04 / 14.04 users to install software LyX document processing (Linux)

- MySQL rollback insert statement causes ibd file grows double (Database)

- Repair after installing Ubuntu no boot device error (Linux)

- What happens after the MySQL disk space is full (Database)

- ogg Oracle to SQL Server 2005 to achieve synchronization (Database)

- Java enum use (Programming)

- Under CentOS using yum command to install the Task Scheduler crontab (Linux)

- CentOS How to mount the hard drive (Linux)

- Android Studio interface-related settings (Linux)

- Linux rpm command Detailed (Linux)

- PostgreSQL 9.4.3 Installation and Configuration under CentOS 6.5 (Database)

- STL spatial Configurator (Programming)

- Monitoring network traffic with Iptraf in Linux environment (Linux)

- iOS9 new feature - stacked view UIStackView (Programming)

- Linux process or thread is bound to a CPU (Programming)

- Python dictionary applications get built-in method (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 {
RED, GREEN, YELLOW, BLUE;
}
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 {
RED, GREEN, YELLOW, BLUE;
}
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

        
    

        
    
note:

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.

@Autowired
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:

@Autowired
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.
     
         
         
         
  More:      
 
- PHP parsing algorithm of the interview questions (Programming)
- An Analysis of the C Algorithm for Calculating the Number of Days Between Date (Programming)
- ARM assembler instruction debugging method (Programming)
- Java List add duplicate the same object (Programming)
- Disk partition MBR (Linux)
- How to Create a file can not be changed under Linux (Linux)
- About Hibernate cache, you want the latest data have trouble even session.clear (Database)
- Linux kernel likely and unlikely to resolve macro definitions (Linux)
- C # socket udp broadcast (Programming)
- Oracle 11g maintenance partitions (Seven) - Modifying Real Attributes of Partitions (Database)
- Android Activity launchMode (Programming)
- A command to install Sublime Text 3 on Manjaro / Archlinux (Linux)
- How to release the cache memory on Linux (Linux)
- Fatal NI connect error 12170 error in Alert Log (Database)
- C # / iOS / Android Universal Encryption and decryption (Programming)
- Upgrade to Node V4 seven reasons (Programming)
- After CentOS configure SSH password Free, still prompted for a password (Linux)
- to install the deployment of LVS under CentOS 7.0 (Server)
- Mahout source code analysis: FP-Growth algorithm parallelization (Programming)
- Use read command to read user input (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.