お世話になっております。spring bootを勉強しております。
ECサイトハンズオンにてECサイトを作成しながら勉強しているのですが、ソースコードに疑問が発生したため質問致します。
以下にソースの階層を示します。
$ tree . ├── pom.xml └── src ├── main │ ├── java │ │ └── jsug │ │ ├── App.java ... Spring Bootアプリケーションのエンドポイント │ │ ├── AppConfig.java ... 今回のアプリケーション用のBean定義ファイル │ │ ├── SecurityConfig.java ... 認証・認可(Spring Security)用のBean定義ファイル │ │ └── domain │ │ ├── model ... ドメインオブジェクトを格納するパッケージ │ │ │ ├── Account.java ... アカウントモデル │ │ │ ├── Cart.java ... カートモデル │ │ │ ├── Category.java ... カテゴリーモデル │ │ │ ├── Goods.java ... 商品モデル │ │ │ ├── Order.java ... 注文モデル │ │ │ ├── OrderLine.java ... 注文行(1行)モデル │ │ │ └── OrderLines.java ... 注文行(複数)モデル │ │ ├── repository ... レポジトリクラスを格納するパッケージ │ │ │ ├── SqlFinder.java ... SQLファイルから、SQL文を取得するためのヘルパー │ │ │ ├── account │ │ │ │ └── AccountRepository.java ... アカウントモデルのデータアクセス(CRUD)用クラス │ │ │ ├── category │ │ │ │ └── CategoryRepository.java ... カテゴリモデルのデータアクセス(CRUD)用クラス │ │ │ ├── goods │ │ │ │ └── GoodsRepository.java ... 商品モデルのデータアクセス(CRUD)用クラス │ │ │ └── order │ │ │ └── OrderRepository.java ... 注文モデルのデータアクセス(CRUD)用クラス │ │ ├── service ... サービスクラスを格納するパッケージ │ │ │ ├── account │ │ │ │ └── AccountService.java ... アカウントのサービスクラス │ │ │ ├── category │ │ │ │ └── CategoryService.java ... カテゴリのサービスクラス │ │ │ ├── goods │ │ │ │ ├── GoodsNotFoundException.java ... 商品が見つからない場合の例外クラス │ │ │ │ └── GoodsService.java ... 商品のサービスクラス │ │ │ ├── order │ │ │ │ ├── EmptyCartOrderException.java ... カートが空の場合の例外クラス │ │ │ │ ├── InvalidCartOrderException.java ... カートの状態が不正な場合の例外クラス │ │ │ │ └── OrderService.java ... 注文のサービスクラス │ │ │ └── userdetails │ │ │ ├── ShopUserDetails.java ... 認証ユーザークラス │ │ │ └── ShopUserDetailsService.java ... 認証ユーザー取得サービスクラス │ │ └── validation ... カスタムBeanValidationルールを格納するパッケージ │ │ ├── Confirm.java ... 2つのフィールドが同じ値であることの制約を示すアノテーション │ │ ├── ConfirmValidator.java ... 2つのフィールドが同じ値であることを検証するバリデータ │ │ ├── UnusedEmail.java ... E-mailが使用されていないことの制約を示すアノテーション │ │ └── UnusedEmailValidator.java ... E-mailが使用されていないことを検証するバリデータ │ └── resources │ ├── application.properties ... アプリケーションの設定ファイル │ ├── db ... FlywayによるDBマイグレーション用のSQLファイル │ │ └── migration │ │ ├── V1__create-schema.sql │ │ └── V2__initial-data.sql │ ├── log4jdbc.log4j2.properties ... Log4JDBCの設定ファイル │ ├── sql ... リポジトリ用のSQLファイル │ │ ├── account │ │ │ ├── countByEmail.sql │ │ │ ├── create.sql │ │ │ └── findOne.sql │ │ ├── category │ │ │ └── findAll.sql │ │ ├── goods │ │ │ ├── countByCategoryId.sql │ │ │ ├── findByCategoryId.sql │ │ │ └── findOne.sql │ │ ├── order │ │ │ └── create.sql │ │ └── orderLine │ │ └── create.sql │ ├── static ... 静的ファイル │ │ ├── css │ │ │ └── wro.css │ │ ├── fonts │ │ │ ├── montserrat-webfont.eot │ │ │ ├── montserrat-webfont.svg │ │ │ ├── montserrat-webfont.ttf │ │ │ ├── montserrat-webfont.woff │ │ │ ├── varela_round-webfont.eot │ │ │ ├── varela_round-webfont.svg │ │ │ ├── varela_round-webfont.ttf │ │ │ └── varela_round-webfont.woff │ │ └── images │ │ ├── 404-icon.png │ │ ├── homepage-bg.jpg │ │ ├── platform-bg.png │ │ ├── platform-spring-xd.png │ │ ├── spring-logo-xd-mobile.png │ │ └── spring-logo-xd.png │ └── templates ... Thyemeleafのテンプレート │ ├── account │ │ ├── createFinish.html ... アカウント作成完了画面 │ │ └── createForm.html ... アカウント作成フォーム画面 │ ├── cart │ │ └── viewCart.html ... カート確認画面 │ ├── goods │ │ ├── notFound.html ... 商品が見つからない場合のエラー画面 │ │ └── showGoods.html ... 商品一覧画面 │ ├── login │ │ └── loginForm.html ... ログインフォーム画面 │ └── order │ ├── confirm.html ... 注文確認画面 │ ├── error.html ... 注文エラー画面 │ └── finish.html ... 注文確認画面 └── test ├── java │ └── jsug │ └── domain │ ├── TestConfig.java ... ユニットテスト用のBean定義ファイル │ ├── model ... ドメインオブジェクトのJUnitコードを格納するパッケージ │ │ └── CartTest.java │ ├── repository ... レポジトリクラスのJUnitコードを格納するパッケージ │ │ ├── account │ │ │ └── AccountRepositoryTest.java │ │ ├── category │ │ │ └── CategoryRepositoryTest.java │ │ ├── goods │ │ │ └── GoodsRepositoryTest.java │ │ └── order │ │ └── OrderRepositoryTest.java │ └── service ... サービスクラスのJUnitコードを格納するパッケージ │ ├── account │ │ └── AccountServiceTest.java │ ├── goods │ │ └── GoodsServiceTest.java │ ├── order │ │ └── OrderServiceTest.java │ └── userdetails │ └── ShopUserDetailsServiceTest.java └── resources ├── logback.xml ... ユニットテスト用Logback設定ファイル └── sql ... テストデータ作成用のSQLファイル ├── drop-tables.sql ├── insert-accounts.sql ├── insert-category.sql ├── insert-goods.sql └── insert-orders.sql
SqlFinder.javaにて「log」という変数(インスタンス?)を使用しているのですが、SqlFinder.java内には「log」の変数宣言はないのです。こちらもアノテーションにてインスタンスの生成の記述が不要とか、そういう仕組みがあるのでしょうか?
logの宣言箇所を調べようと思ったのですがエディターとして使用しているeclipse自体もあまり慣れていないためまだ宣言箇所を特定できておりません。。。
SqlFinder
1package demo.domain.repository; 2 3import lombok.extern.slf4j.Slf4j; 4import org.springframework.cache.annotation.Cacheable; 5import org.springframework.core.io.ClassPathResource; 6import org.springframework.core.io.Resource; 7import org.springframework.stereotype.Component; 8import org.springframework.util.StreamUtils; 9 10import java.io.IOException; 11import java.io.InputStream; 12import java.nio.charset.StandardCharsets; 13 14@Component 15@Slf4j 16public class SqlFinder { 17 18 @Cacheable("sql") 19 public String get(String path) { 20 Resource resource = new ClassPathResource(path); 21 log.info("load {}", resource); //ここで使えているのはなぜ?? 22 try (InputStream stream = resource.getInputStream()) { 23 return StreamUtils.copyToString(stream, StandardCharsets.UTF_8); 24 } catch (IOException e) { 25 throw new IllegalArgumentException(path + " is not found!", e); 26 } 27 } 28} 29
回答1件
あなたの回答
tips
プレビュー