Monday, June 8, 2015

Change MongoDB server port in CentOS 6.6

To change MongoDB server port in CentOS 6.6,

edit the following configuration:

sudo vi /etc/mongod.conf

port=10000

Restart the MongoDB server (mongod) as follows:

sudo /sbin/service mongod start

Reference:
http://docs.mongodb.org/manual/reference/configuration-options/

Install MongoDB on CentOS 6.6

To install MongoDB on CentOS 6.6,

you add MongoDB repository as follows:

sudo vi /etc/yum.repos.d/mongodb-org-3.0.repo

[mongodb-org-3.0]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
gpgcheck=0
enabled=1

Install MongoDB by `yum` as follows:

sudo yum install -y mongodb-org

Start MongoDB by `service` as follows:

sudo /sbin/service mongod start

Check listening port as follows:

sudo vi /var/log/mongodb/mongod.log

2015-06-08T21:14:23.908+0900 I NETWORK  [initandlisten] waiting for connections on port 27017

Run MongoDB client as follows:

mongo

Reference:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/

java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52

When you are using Spring Data MongoDB,

you can encounter the following exception:

Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)

It happened by adding `@Repository` accidentally as follows:

@Repository
public interface SomethingRepository extends MongoRepository<Something, String> {
}

Removing `@Repository` fixes the problem.

It would be better to have an exception having better explanation if possible.

Reference:
https://github.com/spring-projects/spring-boot/issues/1929

Hotfix KB2731284 or later update is not installed, will zero-out data files

When you run a MongoDB server (mongod) in Windows,

you can encounter the following error:

C:\Program Files\MongoDB\Server\3.0\bin>mongod
2015-06-08T20:29:47.485+0900 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data files
2015-06-08T20:29:47.565+0900 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating
2015-06-08T20:29:47.565+0900 I CONTROL  [initandlisten] dbexit:  rc: 100

You can fix it by creating the following directory:

C:\data\db

Unfortunately I can't understand why it fixed the problem.

Anyone who explains why?

Reference:
http://stackoverflow.com/questions/29316482/mongo-error-on-i-control-hotfix

Saturday, June 6, 2015

Show all sub-projects' dependencies in Gradle

In Gradle, to show all sub-projects' dependencies,

add the following to `build.gradle`.

subprojects {
    task allDependencies(type: DependencyReportTask) {}
}

Now you can use the following command:

gradle allDependencies

Reference:
https://solidsoft.wordpress.com/2014/11/13/gradle-tricks-display-dependencies-for-all-subprojects-in-multi-project-build/

Caused by: java.lang.NoSuchMethodError: org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.hasMappingForPattern(Ljava/lang/String;)Z

You can encounter the following error:

Caused by: java.lang.NoSuchMethodError: org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.hasMappingForPattern(Ljava/lang/String;)Z
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addResourceHandlers(WebMvcAutoConfiguration.java:256)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.addResourceHandlers(WebMvcConfigurerComposite.java:102)

Using `gradle dependencies` didn't help me much.

It showed the right dependency I expected:

org.springframework:spring-webmvc:4.1.6.RELEASE

It's one of Gradle sub-projects.

It is caused by another sub-project which it depends on.

The sub-project has a dependency having the following transitive dependency:

org.springframework.mobile:spring-mobile-device:1.1.3.RELEASE

And it has the following transitive dependency:

org.springframework:spring-webmvc:3.2.11.RELEASE

So the conflict occurred.

I solved it as follows:

    compile("xxx:xxx:1.0.0") {
        exclude module: 'spring-mobile-device'
    }

But I can't understand why the latest dependency doesn't win.

Tuesday, June 2, 2015

Show disk usages of all directories in Windows

If you want to know disk usages of all directories in Windows,

you can use `WinDirStat`.

I used it to find directories using a lot of space and it nicely worked.

Reference:
http://windirstat.info/