This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <beans xmlns="http://www.springframework.org/schema/beans" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xmlns:context="http://www.springframework.org/schema/context" | |
| xsi:schemaLocation="http://www.springframework.org/schema/beans | |
| http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | |
| http://www.springframework.org/schema/context | |
| http://www.springframework.org/schema/context/spring-context.xsd"> | |
| <context:component-scan base-package="com.pig.spring.basics" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps.Scope; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.stereotype.Component; | |
| @Component | |
| public class PersonDAO { | |
| @Autowired | |
| JdbcConnection jdbcConnection; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps.Scope; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.stereotype.Repository; | |
| @Repository //<--改這裡 | |
| public class PersonDAO { | |
| @Autowired | |
| JdbcConnection jdbcConnection; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.componentscan; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.stereotype.Repository; | |
| @Repository //<--改這裡 | |
| public class ComponentDAO { | |
| @Autowired | |
| ComponentJdbcConnection jdbcConnection; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps.Basic; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.beans.factory.annotation.Qualifier; | |
| import org.springframework.beans.factory.config.ConfigurableBeanFactory; | |
| import org.springframework.context.annotation.Scope; | |
| import org.springframework.stereotype.Service; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps.Basic; | |
| import org.springframework.beans.factory.annotation.Qualifier; | |
| import org.springframework.stereotype.Service; | |
| @Service //<-改這裡 | |
| @Qualifier("bubble") | |
| public class BubbleSortAlgorithm implements SortAlgorithm{ | |
| public int[] sort(int[] numbers) { | |
| // Logic for Bubble Sort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps.Basic; | |
| import org.springframework.beans.factory.annotation.Qualifier; | |
| import org.springframework.stereotype.Service; | |
| @Service //<-改這裡 | |
| @Qualifier("quick") | |
| public class QuickSortAlgorithm implements SortAlgorithm{ | |
| public int[] sort(int[] numbers) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps.properties; | |
| import org.springframework.beans.factory.annotation.Value; | |
| import org.springframework.stereotype.Component; | |
| @Component //<-要讓Spring找到所以要有宣告是Component | |
| public class SomeExternalService { | |
| @Value("${erternal.service.url}") //<-預計在設定檔內的key值 | |
| private String url; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| erternal.service.url=http://someserver.dev.com/service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.spring.basics.springin5steps; | |
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |
| import org.springframework.context.annotation.ComponentScan; | |
| import org.springframework.context.annotation.Configuration; | |
| import org.springframework.context.annotation.PropertySource; | |
| import com.pig.spring.basics.springin5steps.properties.SomeExternalService; | |
| @Configuration |