AppConfig.java
セキュリティのために注釈スキャンなしで、ハードバインディングのために構成なしで、次のようなSpring Beanのインスタンスをapp-config.xml
作成します。
@Configuration
public class AppConfig {
@Bean
public AddressService addressService(){
return new AddressService();
}
}
すべてがうまく機能しますが、他の人がのインスタンスを作成できないようにしたい場合はどうすればよいAddressService
ですか? AddressService
通常、コンストラクターをプライベートに宣言しますが、コンパイラーは、プライベートコンストラクターにアクセスできないというエラーを表示し AppConfig
ます!
完全を期すために、これは次のAddressService
とおりです。
public final class AddressService {
private AddressService(){}
}