# @PropertySource
| @SuppressWarnings("all") |
| |
| @Configuration |
| |
| @ComponentScan("com.dkx.spring") |
| |
| @PropertySource("a.properties") |
| public class SpringConfig { |
| } |
| @SuppressWarnings("all") |
| @Repository("bookDao1") |
| public class BookDaoImpl implements BookDao { |
| @Value("${name}") |
| private String name; |
| |
| public void save(){ |
| System.out.println("BookDaoImpl save rning..."+","+name); |
| } |
| } |
| @SuppressWarnings("all") |
| @Service("bookService") |
| public class BookServiceImpl implements BookService { |
| @Autowired |
| @Qualifier("bookDao1") |
| private BookDao bookDao; |
| public void save(){ |
| System.out.println("BookServiceImpl save rning..."); |
| bookDao.save(); |
| } |
| } |
| public void test(){ |
| ApplicationContext c = new AnnotationConfigApplicationContext(SpringConfig.class); |
| BookService service = c.getBean("bookService",BookService.class); |
| service.save(); |
| } |
Run Result
# 使用 claspath *
: *
(Error)
可使用 classpath: 而不可使用 classpath*:*
| @SuppressWarnings("all") |
| |
| @Configuration |
| |
| @ComponentScan("com.dkx.spring") |
| |
| @PropertySource("classpath*:*properties") |
| public class SpringConfig { |
| } |
Run Result