java - Is spring getbean case sentitive or not? -
when use getbean("test")
i have class like
@component public class test { } can bean loaded?
getbean() is case sensitive, spring uses custom bean naming strategy @component , @bean classes. see 4.10.5 naming autodetected components:
when component autodetected part of scanning process, bean name generated
beannamegeneratorstrategy [...]. default, spring stereotype annotation (@component,@repository,@service, ,@controller) containsnamevalue thereby provide name corresponding bean definition.if such annotation contains no
namevalue or other detected component (such discovered custom filters), default bean name generator returns uncapitalized non-qualified class name.
and @configuration/@bean see 4.12.4.5 customizing bean naming:
by default, configuration classes use
@beanmethod's name name of resulting bean. functionality can overridden, however,nameattribute.
back question. because class not following java naming conventions (camel-case names) spring uses unusual name bean, work:
getbean("test") however if use expected naming (@component class test { }), must use lower-case identifiers:
getbean("test") moreover if name more complex, uncapitalized camel-case syntax applies (continuing quote spring documentation):
[...] example, if following 2 components detected, names
mymovielister,moviefinderimpl:
@service("mymovielister") public class simplemovielister { // ... } @repository public class moviefinderimpl implements moviefinder { // ... }
Comments
Post a Comment