Spring Bean 枚举属性注入

Stella981
• 阅读 668

1、名称空间配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

2、JAVA

package com.demo.bean;

class TestBean {

    private Gender gender

    public void setGender(Gender gender){
        this.gender = gender;
    }

    public Gender getGender(){
        return gender;
    }

}

package com.demo.utils;

public enum Gender {
    MALE, FEMALE, UNSPECIFIED
}

3、Bean 配置

<bean id="testBean" class="com.demo.bean.TestBean">
    <property name="gender" ref="gender" />
</bean>
<util:constant id="gender" static-field="com.demo.utils.MALE" />
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
2年前
ssm框架整合
applicationContext.xml<beansxmlns"http://www.springframework.org/schema/beans"xmlns:context"http://www.springframework.org/schema/context"xmlns:p"http://www.springframew
Easter79 Easter79
2年前
spring集成JMS activeMQ 头文件
<beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"xmlns:amq"http://activemq.apache.org/schema/core"
Stella981 Stella981
2年前
Spring MVC 配置文件dispatcher
1.<?xmlversion\"1.0"encoding\"UTF8"?2.<beansxmlns\"http://www.springframework.org/schema/beans"3.xmlns:mvc\"http://www.springframework.org/schema/mvc"4.xml
Stella981 Stella981
2年前
Spring 使用注解方式进行事务管理
使用步骤:步骤一、在spring配置文件中引入<tx:命名空间<beansxmlns"http://www.springframework.org/schema/beans" xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance" xmlns:tx"http
Easter79 Easter79
2年前
Spring错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
背景:学习切面,测试前置通知功能,xml配置如下<?xmlversion"1.0"encoding"UTF8"?<beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http:/
Wesley13 Wesley13
2年前
Spring中hibernateTemplate的使用
1.<?xmlversion\"1.0"encoding\"UTF8"?2.<beansxmlns\"http://www.springframework.org/schema/beans"3.xmlns:xsi\"http://www.w3.org/2001/XMLSchemainstance"xmlns:con
Stella981 Stella981
2年前
Spring Task 定时任务
推荐使用基于配置XML的形式!!!     //首先要定义schema 空间     <?xml version"1.0" encoding"UTF8"?          <beans xmlns"http://www.springframework.org/schema/beans"         
Stella981 Stella981
2年前
Redis在SSM框架的使用(三)
Spring整合springdataredis1、springredis.xml<?xmlversion"1.0"encoding"UTF8"?<beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_