当前位置:首页 > 未命名 > 正文内容

Spring@Service的默认bean名称

淙嶙7年前 (2018-07-24)未命名1104

若类名字为Abc,则生成bean的实例名字为abc

若类名字为ABc,  则生成bean的实例名字为ABc

验证结果,目录:

image.png


LoginService.java (正常类)

package com.dl.study.m2.service;

import org.springframework.stereotype.Service;
@Service
public class LoginService {
    //do something
}

LCheckService.java(前两个字母全大写的)

package com.dl.study.m2.service;

import org.springframework.stereotype.Service;
@Service
public class LCheckService {
    //do something
}

spring-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    ">
    <context:annotation-config/>
    <context:component-scan base-package="com.dl.study.m2.service" />

</beans>

ShowBeanName 展示bean名字

ShowBeanName {
    main(String[] args){
        ApplicationContext context = ClassPathXmlApplicationContext();
       String[] str=context.getBeanDefinitionNames();
        (String string : str) {
            System..println(+string);
        }
    }
}

结果:前两个字母大写的 名字不变,只有首字母大写的首字母变成小写

七月 24, 2018 3:31:42 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@41cf53f9: startup date [Tue Jul 24 15:31:42 CST 2018]; root of context hierarchy
七月 24, 2018 3:31:42 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [E:workspace3dl-study	argetclassesspring-application.xml]
bean name :org.springframework.context.annotation.internalConfigurationAnnotationProcessor
bean name :org.springframework.context.annotation.internalAutowiredAnnotationProcessor
bean name :org.springframework.context.annotation.internalRequiredAnnotationProcessor
bean name :org.springframework.context.annotation.internalCommonAnnotationProcessor
bean name :org.springframework.context.event.internalEventListenerProcessor
bean name :org.springframework.context.event.internalEventListenerFactory
bean name :LCheckService
bean name :loginService
Process finished with exit code 0


相关文章

Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)

Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)

位运算符主要针对二进制,它包括了:“与”、“非”、“或”、“异或”。从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算。下面...

找出单独出现的数字

找出单独出现的数字

描述 给出N个数字。其中仅有一个数字出现过一次,其他数字均出现过两次,找出这个出现且只出现过一次的数字。要求时间和空间复杂度最小。 输入 输入多个数字,每个数字以空格分开,回车结束...

设计模式是什么鬼

设计模式是什么鬼

设计模式是什么鬼?“世界处处不设计”有物混成,先天地生。寂兮寥兮,独立而不改,周行而不殆,可以为天地母。吾不知其名,字之曰道,强为之名曰大。大曰逝,逝曰远,远曰反。道是什么?道可道,非常道。道不明,说...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。