PowerShellでフォルダ比較を行う
PowerShellの中でフォルダの中身を再帰的に比較したいことがあったため、調べた結果をメモ。
diffコマンドがあればこんな苦労はないのだが、PowerShellやWindows標準のコマンドだとかゆいところに手が届かない感じ。
GUIならWinMergeがあるが、今回はPowerShellスクリプトから利用したい。
ググると、下記情報が出てくる。
stackoverflow.com
コードとしては下記の通り。
$d1 = get-childitem -path $dir1 -recurse $d2 = get-childitem -path $dir2 -recurse compare-object $d1 $d2
Get-ChildItemで比較する2フォルダを取得して、そのままCompare-Objectに渡している。
このやり方を試してみると特徴は、
- ファイルの有無を比較できる
- ファイルの内容の比較はできない
- 同一ファイル名が別階層に存在していると差分なし扱いになってしまう
といったところ。
同一ファイル名の別階層を差分なし扱いにするため、今回は下記のように改変して使ってみた。
$d1 = (Get-Childitem -Path $dir1 -Recurse | % { $_.FullName.Replace(("$dir1" + "\"), "") }) $d2 = (Get-Childitem -Path $dir2 -Recurse | % { $_.FullName.Replace(("$dir2" + "\"), "") }) compare-object $d1 $d2
ファイルリストの比較はこれで問題なさそう。
本当はファイル内容の比較も行いたかったがそちらは簡単な書き方が結局見つけられず、普通にループしながらCompare-Objectをひたすら実行することに・・・。
Spring Boot触ってみる その5 ープロファイルを利用した環境ごと設定の切り替えー
Spring Boot触ってみる その4 ーSQLServerへの接続ー - endokのブログ
の続き。
DB接続設定など、実行する環境に応じて切り替えたいパラメータがある。
Springでは"Profile"という仕組みで切り替えることができる。
その1(http://endok.hatenablog.com/entry/2016/06/04/124011)で作成したサンプルプロジェクトを引き続き利用する。
続きを読むSpring Boot触ってみる その4 ーSQLServerへの接続ー
Spring Boot触ってみる その3 ーThymeleaf Layout Dialectでレイアウトを共通化ー - endokのブログ
の続き。
SpringBootでのSQLServerへの接続方法を確認する。
SpringBoot特有の設定ということはなく、Springであれば同じような設定となるだろう。
その1(http://endok.hatenablog.com/entry/2016/06/04/124011)で作成したサンプルプロジェクトを引き続き利用する。
続きを読むSpringで定義済のBean名一覧を出力する
SpringBootはSpringのBean設定を隠蔽してくれているのだが、SpringBoot側で定義しているBeanをInjectionしたいときにはどういったBeanが定義済なのかわからず困る。
定義済のBean名をすべて出力する方法を調べたのでメモ。
方法は下記の通り。
1. BeanFactoryAwareをimplementsして、BeanFactoryを取得する。
2. BeanFactoryをDefaultListableBeanFactoryにキャストして、getBeanDefinitionNamesメソッドを利用する。
Controllerで実装した場合の例はこのようになる。
@Controller public class HelloController implements BeanFactoryAware { private DefaultListableBeanFactory beanFactory; @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { this.beanFactory = (DefaultListableBeanFactory)beanFactory; } @RequestMapping(value = "/page1") public String page1() { for (String name : beanFactory.getBeanDefinitionNames()) { System.out.println(name); } return "page1"; } }
Spring Boot触ってみる その3 ーThymeleaf Layout Dialectでレイアウトを共通化ー
Spring Boot触ってみる その2 ーController,テンプレートエンジン(Thymeleaf)ー - endokのブログ
の続き。
Thymeleafにもincludeなどを使った共通化の仕組みはあるが、
各ページごとにincludeは書きたくない・・・。
Tilesのように共通レイアウトを定義する仕組みはないものかと調べたところ、
Thymeleaf Layout Dialect(https://github.com/ultraq/thymeleaf-layout-dialect)というものがあったため試してみる。
その1(http://endok.hatenablog.com/entry/2016/06/04/124011)で作成したサンプルプロジェクトを引き続き利用する。
続きを読むSpringBootの開発に自動リロード(ホットデプロイ)を導入する
目次
- 目次
- はじめに
- SpringLoaded
- 特徴
- 導入方法
- Spring Boot Dev Tools
- 特徴
- 導入方法
- まとめ
はじめに
SpringBootの開発の流れは、
1. コードを書く
2. [Run As]→[Spring Boot App]で起動
3. 動作確認する
4. コードを書く
5. Consoleから起動中のアプリをTerminate
6. [Run As]→[Spring Boot App]で起動
7. 3に戻る
としていたが、
いちいち修正を反映するのに停止して起動するのは煩わしい。
1つ処理を書くたびに動作確認したいタイプなので、開発効率が悪くなってしまう。
S2Containerにはホットデプロイあって楽だったなぁ・・・と思ったので同様の仕組みを調べてみた。
- JRebel(http://samuraism.com/products/zeroturnaround/jrebel)
- SpringLoaded(https://github.com/spring-projects/spring-loaded)
- SpringBootDevTools(http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html)
Springという名前が付いているし、JRebelは商用(myJRebelというフリー版もあるようだが)なので、SpringLoadedとSpringBootDevToolsを試してみる。
SpringToolSuiteでpom.xmlのdependencyを追加しても実行時に認識されない
SpringBootでDBアクセスをしようとしていたときのこと。
pom.xmlに下記記述を追加した。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>runtime</scope> </dependency>
Repositoryクラスを作って下記のようにinjectionしてみるが、実行時にエラーが発生する。
@Autowired
MemberRepository repository;
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
>Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
ということで、組み込みDBであればクラスパスに配置さえしていれば問題なさそうである。
今回pom.xmlにhsqldbを追加しているため、クラスパスは通っているはず。
同じような症状をググっていき、最終的には
maven - Error running Basic Spring Batch example - Caused by: java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver - Stack Overflow
に記載のあった、
>learing my entire local repository and then rebuilding has fixed the problem
を試したら解消した。
具体的には、Mavenのローカルレポジトリ内のファイルをすべて消したあとに再度実行すると解消していた。(ソースコードや設定は変更なし)
Mavenのローカルレポジトリの場所はPreferencesの[Maven]→[User Settings]のLocal Repositoryにパスが書いてある。
EclipseでMavenを利用した際に起きるようだが、こういったキャッシュ周り?の問題は非常に原因が掴みづらくて困る。