Chen Jian's Java Blog 

Things to do for a serious Java website when using Elastic Beanstalk

by Chen Jian


Posted on 2018-11-25 12:00 in Java


Before you start Get a domain If you haven't got one, you can buy one. You can get it from AWS Route 53 Get a SSL certificate for your domain You can get it from AWS Certificate Manager. Create an IAM User You will need this...


"model" doesn't work but "it" works when using sitemesh + jersey mvc + jsp

by Chen Jian


Posted on 2018-11-18 12:00 in Java


When I use "model" for the attribute name in the Jsp views, it only works in the original view, but not in other parts of the whole, merged view. But when I use "it" instead, everything works. I don't know why. Maybe Jersey removes "model" from...


Dynamic file name in log4j's file appender

by Chen Jian


Posted on 2018-06-17 12:00 in Java


In your log4j.xml, set the file name as a variable <appender name="my-file-appender" class="org.apache.log4j.FileAppender"> <param name="file" value="${myFilePath}" /> <!-- ... --> </appender> Then in your java...


Quick log4j set up

by Chen Jian


Posted on 2018-06-17 12:00 in Java


<!-- pom.xml --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>org.slf...


How to prevent Quartz from re-firing a job while it is still running

by Chen Jian


Posted on 2018-06-04 12:00 in Java


Answer: use @DisallowConcurrentExecution Example Without this annotation import java.time.LocalTime; import org.quartz.DisallowConcurrentExecution; import org.quartz.Job; import org.quartz.JobExecutionContext; import...


Quartz concepts

by Chen Jian


Posted on 2018-06-04 12:00 in Java


Basic concepts Job: What to do Trigger: When to do it Scheduler: The director to associate triggers to jobs and to invoke the trigger A job can be associated with several triggers, but a...


Forwarded servlet request won't be intercepted by filters

by Chen Jian


Posted on 2017-12-13 12:00 in Java


The new request created by RequestDispatcher.forward(request, response) will not be intercepted by its matching filters defined in web.xml To make a filter work for requests created by dispatcher, you have to add 2 dispatcher configurations to your...


Declare data source as JNDI name in Spring's integration tests

by Chen Jian


Posted on 2017-07-18 12:00 in Java


SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); builder.bind(jndiName, dataSource); builder.activate();


There are two Application Contexts in Spring MVC apps

by Chen Jian


Posted on 2017-07-17 12:00 in Java


The root context, normally seen as biz-layer context, is normally defined as "applicationContext.xml" and loaded by ContextLoaderListener.  The other context, the web-layer one is normally defined as "mvc-servlet.xml" and loaded...


List.iterator() returns a new Iterator every time

by Chen Jian


Posted on 2017-05-19 12:00 in Java


List list = Arrays.asList("a","b", "c"); System.out.println(list.iterator().next()); // "a" System.out.println(list.iterator().next()); // still "a"


Wildfly wierd feature in 8.2.0 -- automatic redirect if your path matches a directory under your webapp

by Chen Jian


Posted on 2017-04-06 12:00 in Java


1. If there is a directory "abc" under your webapp root directory and there is no index.jsp under this "abc" directory 2. and you request http://xxx/abc regardless of GET or POST method 3. then wildfly will redirect...


Spring + TestNG + @Spy Example

by Chen Jian


Posted on 2016-12-01 12:00 in Java


@ContextConfiguration({"/spring/applicationContext.xml"}) public class SprintTestngWithSpyAnnotationITCase extends AbstractTestNGSpringContextTests { //this bean will take mocked objects injected into it, but it itself is not going to be mocked ...


TestNg: When will @BeforeClass, @BeforeMethod, @BeforeTest be run and in what sequence?

by Chen Jian


Posted on 2016-11-30 12:00 in Java


public class KentNg { @DataProvider(name = "someData") public Object[][] someData() { return new Object[][]{ {"a1", "b1"}, {"a2", "b2"} }; } @BeforeTest public void...


Mockito.spy() will not work with cglib-enhanced objects

by Chen Jian


Posted on 2016-11-28 12:00 in Java


Mockito.spy() will not work with cglib-enhanced objects , even if you use doReturn() instead of thenReturn(). This can cause problems in spring + @Transactional + cblig situations. As a result, you can't simply use @Transactional in your code, but...


For integration testing's sake, use one interface + one implemenation

by Chen Jian


Posted on 2016-11-25 12:00 in Java


With mocking technology today, you may dismiss the idea of 'one interface + one implementation' paradigm. In fact, you may still appreciate this way of code organization. Let me ask you a question: how to test a non-public method ? For unit...