File tree Expand file tree Collapse file tree
main/java/com/baeldung/factorybean
test/java/com/baeldung/factorybean Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66@ Configuration
77public class FactoryBeanAppConfig {
88
9- @ Bean
9+ @ Bean ( name = "tool" )
1010 public ToolFactory toolFactory () {
1111 ToolFactory factory = new ToolFactory ();
1212 factory .setFactoryId (7070 );
1313 factory .setToolId (2 );
1414 return factory ;
1515 }
16-
17- @ Bean
18- public Tool tool () throws Exception {
19- return toolFactory ().getObject ();
20- }
2116}
Original file line number Diff line number Diff line change 77
88import org .junit .Test ;
99import org .junit .runner .RunWith ;
10+ import org .springframework .beans .factory .annotation .Autowired ;
11+ import org .springframework .beans .factory .annotation .Qualifier ;
1012import org .springframework .test .context .ContextConfiguration ;
1113import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
1214
1315@ RunWith (SpringJUnit4ClassRunner .class )
1416@ ContextConfiguration (classes = FactoryBeanAppConfig .class )
1517public class FactoryBeanJavaConfigTest {
1618
17- @ Resource
19+ @ Autowired
1820 private Tool tool ;
19- @ Resource (name = "&toolFactory " )
21+ @ Resource (name = "&tool " )
2022 private ToolFactory toolFactory ;
2123
2224 @ Test
Original file line number Diff line number Diff line change 77
88import org .junit .Test ;
99import org .junit .runner .RunWith ;
10+ import org .springframework .beans .factory .annotation .Autowired ;
1011import org .springframework .test .context .ContextConfiguration ;
1112import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
1213
1314@ RunWith (SpringJUnit4ClassRunner .class )
1415@ ContextConfiguration (locations = { "classpath:factorybean-spring-ctx.xml" })
1516public class FactoryBeanXmlConfigTest {
1617
17- @ Resource
18+ @ Autowired
1819 private Tool tool ;
1920 @ Resource (name = "&tool" )
2021 private ToolFactory toolFactory ;
You can’t perform that action at this time.
0 commit comments