Posts

Showing posts from July, 2012

Spring DI with different styles

Spring as a dependency injection (DI) framework allows us to define our application components' dependency tree in three different ways: XML Annotation Java Config I've written a simple app, bookstore, with the three styles and they're available in the following repository. You can take a look and see how each style would look like. It also has a version that uses no Spring beans for comparison. https://github.com/ryu1kn/spring--working-with-beans Different styles have different pros/cons. Spring lets you mix the styles; so you can change it as you go. Here is my observations on each style. XML-based configuration Pros Weak/loose coupling with Spring framework in your app code. Good for keeping the option of removing Spring later Class dependency information is centralised. Fine-grained control on the dependency definition. Changing only the dependency information doesn't require the recompilation of your app code. Cons Unless you have a good IDE

Vim + Syntastic + JSHint

Vim で JSHint を使えるようにする話。 Vim でコードのチェックをするのにどのプラグインを使うかで、評判のよい Syntastic を使うことにした。GitHub で公開されてて、 Vim への追加も簡単。 1. JSHint をインストール まずコマンドラインから JSHint を使えるようにする。 $ npm install jshint -g Stackoverflow の以下の投稿で、 JSHint を vim で使うための方法が書かれてる。 javascript - VIM + JSLint? - Stack Overflow, Community-driven jshint.com (better than JSLint) ここでは .jshintrc というファイルを $HOME に置くようにと言ってる。そしてそのサンプルが紹介されてる。ただしこのサンプル、プロパティ "predef" 内に余分なカンマ (,) があり(22行目)、このままだと Syntastic を使うときに正しく文法チェックをしてくれないので、カンマは消した上で保存した。 早速 JSHint を使ってみる。試しに何か文法エラーを含む JavaScript ファイルを作ってそれをチェックする。 $ jshint js-with-errors.js ソースコードの問題点がターミナルに列挙されていればok。 2. Syntastic を Vim に追加 自分は Vim でのパッケージ管理に NeoBundle を使ってる。なので、 .vimrc に次のように書き込み Syntastic を追加する。 NeoBundle 'scrooloose/syntastic' .vimrc を保存し、 vim を再起動。 :NeoBundleInstall で Syntastic のインストールが完了。 3. Syntastic の設定 Syntastic は JavaScirpt 以外にも色々な言語のソースをチェックすることができる。以下では JavaScript のチェックだけ自動で行われるようにしてる。また、 JavaScript のソースチェックに JSHint を使いたいので、