728x90
Inner Class๋ฅผ ์คํ๋ง ๋น์ผ๋ก ๋ฑ๋กํ๋ ๊ฒฝ์ฐ static ํค์๋๋ฅผ ๋ถ์ฌ์ฃผ์ง ์์ผ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๋ค์ ์ฝ๋๋ฅผ ํตํด ํ์ธํ๊ฒ ์ต๋๋ค.
@SpringBootTest
class InnerClassTests {
@Test
void AutowiredOption() {
ApplicationContext ac = new AnnotationConfigApplicationContext(InnerClass.class);
}
class InnerClass {
@Autowired
public void setNoBean1(){}
}
}
๋ฐ์ํ๋ ์ค๋ฅ
UnsatisfiedDependencyException: Error creating bean with name 'InnerClassTests.InnerClass': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.cnupost.cnupost.InnerClassTests' available: expected at least 1 bean which qualifies as autowire candidate.
InnerClass๋ฅผ static ํด๋์ค๋ก ๋ฐ๊พธ์ด์ฃผ๋ฉด ํด๊ฒฐ๋ฉ๋๋ค.
์ด์ ๋ ์๋ Reference๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์
Reference
728x90