1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

beanのクラス名が重複したとき

Posted at

コンパイルが通っても、実行時にエラーとなるため、重複しない名前をつけないといけない。1つ1つ手でつけると間違いが起こりやすいため、自動で付けるようにする。

##ルートパス直下等に名前付けクラスを定義

FQCNBeanNameGenerator.java
public class FQCNBeanNameGenerator extends AnnotationBeanNameGenerator {

    @Override
    protected String buildDefaultBeanName(BeanDefinition definition) {
        return definition.getBeanClassName();
    }
}

##servlet-context.xmlを変更

変更前:servlet-context.xml
	<context:component-scan base-package="jp.co.test" />
変更後:servlet-context.xml
	<context:component-scan
		base-package="jp.co.test"
		 name-generator="jp.co.test.FQCNBeanNameGenerator" />

##参考

https://qiita.com/sinsengumi/items/655d9f3ff49646dfe61a
http://d.hatena.ne.jp/ocs/20101129/1291034951

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?