Google Chrome displays pink color screen

Problem After upgrading from Windows 8 Enterprise to Windows 8.1, Google Chrome displays pink color screen like this : Windows Environment Chrome 34.0.1847.137 m Windows 8.1 NVIDIA 331.58 Chrome GPU : NVIDIA 9.18.13.3158 To get the Chrome GPU, type chrome://gpu in the browser URL, refer to the driver version. Driver vendor NVIDIA Driver version 9.18.13.3523 …

Read more

ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

Spring + Hibernate4 integration, and transaction are managed by Spring AOP, example : spring-hibernate.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="userDaoPointCut" expression="execution(* com.mkyong.users.service.*Dao.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="userDaoPointCut" /> …

Read more

Spring Security : Check if user is from remember me cookie

This Spring Security example shows you how to check if a user is login from a “remember me” cookie. private boolean isRememberMeAuthenticated() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return false; } return RememberMeAuthenticationToken.class.isAssignableFrom(authentication.getClass()); } @RequestMapping(value = "/admin/update**", method = RequestMethod.GET) public ModelAndView updatePage() { ModelAndView model = new ModelAndView(); if (isRememberMeAuthenticated()) …

Read more

Spring + Hibernate : No Session found for current thread

Integrates Spring 3 and Hibernate 4, the system shows the following message while performing database operation : org.hibernate.HibernateException: No Session found for current thread The sessionFactory is injected like this : spring-hibernate4.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" …

Read more

How to autowire DataSource in JdbcDaoSupport

A Simple DAO class extends JdbcDaoSupport, but, unable to inject or @autowired a “dataSource”, the method setDataSource is final, can’t override. UserDetailsDaoImpl.java package com.mkyong.users.dao; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.stereotype.Repository; @Repository public class UserDetailsDaoImpl extends JdbcDaoSupport implements UserDetailsDao { //Error, cannot override the final method from JdbcDaoSupport @Autowired public void setDataSource(DataSource dataSource) { …

Read more

Can’t delete records in MySQL Workbench

In MySQL workbench, issue a simple delete all commands delete FROM users; But it shows me following error message : Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL …

Read more

JdbcTemplate queryForInt() is Deprecated

Upgrading Spring version and noticed that queryForInt() is deprecated, what should be replaced by? private boolean isUserExists(String username) { String sql = "SELECT count(*) FROM USERS WHERE username = ?"; boolean result = false; //The method queryForInt(String, Object…) from the type JdbcTemplate is deprecated int count = getJdbcTemplate().queryForInt(sql, new Object[] { username }); if (count …

Read more

Python – Read XML file (DOM Example)

In this example, we will show you how to read an XML file and print out its values, via Python xml.dom.minidom. 1. XML File A simple XML file, later parse it with Python minidom. staff.xml <?xml version="1.0"?> <company> <name>Mkyong Enterprise</name> <staff id="1001"> <nickname>mkyong</nickname> <salary>100,000</salary> </staff> <staff id="1002"> <nickname>yflow</nickname> <salary>200,000</salary> </staff> <staff id="1003"> <nickname>alex</nickname> <salary>20,000</salary> </staff> …

Read more

queryForObject() throws EmptyResultDataAccessException when record not found

Reviewing a legacy project, and found this Spring JDBC code snippets : public User getUser(String username) { String sql = "SELECT * FROM USER WHERE username = ?"; return getJdbcTemplate().queryForObject( sql, new Object[] { username }, new RowMapper<UserAttempts>() { public UserAttempts mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); …

Read more

How to install a Vim color scheme

In this tutorial, we will show you how to install a Vim editor color scheme named “distinguished“. 1. Default Color Scheme Default syntax highlight in the “homebrew” profile terminal. 2. Install a new Vim Color Scheme 2.1 Download a new Vim color scheme – “distinguished“. Extracts and move the downloaded *.vim file to this folder …

Read more

The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

Developing a Spring MVC, using a JSP file as a View resource. example.jsp <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <body> <h1>Spring MVC web application</h1> </body> </html> Above is a simple JSP page, but hits the following jstl error? SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either …

Read more

Spring Security Hello World Annotation Example

In preview post, we are using XML files to configure the Spring Security in a Spring MVC environment. In this tutorial, we are going to show you how to convert the previous XML-base Spring Security project into a pure Spring annotation project. Technologies used : Spring 3.2.8.RELEASE Spring Security 3.2.3.RELEASE Eclipse 4.2 JDK 1.6 Maven …

Read more

Eclipse – SimpleTagSupport was not found on the Java Build Path

Here is the development environment Eclipse 4.3 Kepler Java 1.7 Spring 3.2, a MVC project using JSP view. 1. Problem Recently, Eclipse IDE is prompting following error message on top of all of the .tag file. The superclass "javax.servlet.jsp.tagext.SimpleTagSupport" was not found on the Java Build Path. See figure : P.S The SimpleTagSupport class is …

Read more

Java – Get nameservers of a website

In this tutorial, we will show you how to get the nameservers of a website using Java + dig command. 1. Using Dig Command 1.1 On Linux, we can use dig command to query a DNS lookup of a website, for example : $ dig any mkyong.com //… mkyong.com. 299 IN A 162.159.x.x mkyong.com. 299 …

Read more

jConsole – JMX remote access on Tomcat

In this tutorial, we will show you how to use jConsole to remote access a Tomcat instance, for JVM monitoring stuff. Tools and environment used : Ubuntu 13 + Tomcat 7 + 192.168.1.142 Windows 8 + jConsole + 192.168.1.200 1. Tomcat + JMX To connect with jConsole, Tomcat need to enable the JMX options. To …

Read more

Eclipse + Tomcat – java.lang.OutOfMemoryError: Java heap space

In Eclipse IDE, run a Java web application with Tomcat server plugin, but the console prompts Exception in thread "x" java.lang.OutOfMemoryError: Java heap space 1. Solution – Increase Heap Size in Tomcat By default, Tomcat allocated a small amount of heap size. To solve it, you need to increase the Tomcat’s heap size manually. 1.1 …

Read more

Grep for Windows – findstr example

I love grep command on Linux, it helped to search and filter strings easily, always wonder what is the equivalent tool on Windows, and found this findstr recently. In this article, I will share some of my favorite “grep” examples on Linux, and how to “port” it to Windows with “findstr” command. 1. Filter a …

Read more

Find out your Java heap memory size

In this article, we will show you how to use the -XX:+PrintFlagsFinal to find out your heap size detail. In Java, the default and maximum heap size are allocated based on this – ergonomics algorithm. Heap sizes Initial heap size of 1/64 of physical memory up to 1Gbyte Maximum heap size of 1/4 of physical …

Read more

JSP – jsessionid appear in CSS and JS link

In Spring MVC + JSP view page environment. index.jsp <html> <head> <title>Welcome!</title> <c:url var="assets" value="/resources/abc" /> <link href="${assets}/css/style.min.css" rel="stylesheet"> <script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />"> </script> </head> … </html> In the Spring config file, mapped a resource path, mvc-dispatcher-servlet.xml <beans … <context:component-scan base-package="com.mkyong.test" /> <mvc:resources mapping="/resources/**" location="/resources/" /> </beans> 1. Problem After deployed, Spring MVC can’t get …

Read more

Java – Append values into an Object[] array

In this example, we will show you how to append values in Object[] and int[] array. Object[] obj = new Object[] { "a", "b", "c" }; ArrayList<Object> newObj = new ArrayList<Object>(Arrays.asList(obj)); newObj.add("new value"); newObj.add("new value 2"); 1. Object[] Array Example Example to append values with ArrayList : TestApp.java package com.mkyong.test; import java.util.ArrayList; import java.util.Arrays; public …

Read more

Java – Convert int[] to Integer[] example

Examples show you how to convert between int[] and its’ wrapper class Integer[]. 1. Convert int[] to Integer[] public static Integer[] toObject(int[] intArray) { Integer[] result = new Integer[intArray.length]; for (int i = 0; i < intArray.length; i++) { result[i] = Integer.valueOf(intArray[i]); } return result; } 2. Convert Integer[] to int[] public static int[] toPrimitive(Integer[] …

Read more

CloudFlare + WordPress admin, Cache issue

Below is my website environment : WordPress 3.8.1 CloudFlare Pro Plan 1. Problem I’m unable to login WordPress after changing my custom DNS to CloudFlare, below is the error message : ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress P.S The browser’s cookies are enabled. Here’s …

Read more

TestNG + Spring Integration Example

In this tutorial, we will show you how to test Spring’s components with TestNG. Tools used : TestNG 6.8.7 Spring 3.2.2.RELEASE Maven 3 Eclipse IDE 1. Project Dependencies To integrate Spring with TestNG, you need spring-test.jar, add the following : pom.xml <properties> <spring.version>3.2.2.RELEASE</spring.version> <testng.version>6.8.7</testng.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> …

Read more

TestNG – Groups Test

In this tutorial, we will show you how to do the group testing in TestNG. 1. Groups on Methods Review a test group example. runSelenium() and runSelenium1() are belong to group selenium-test. testConnectOracle() and testConnectMsSQL() are belong to group database. runFinal() will be executed if groups selenium-test and database are passed. TestGroup.java package com.mkyong.testng.examples.group; import …

Read more

MongoDB – Aggregate and Group example

In this tutorial, we will show you how to use MongoDB aggregate function to group documents (data). 1. Test Data Data in JSON format, shows the hosting provider for website. website.json { “_id” : 1, “domainName” : “test1.com”, “hosting” : “hostgator.com” } { “_id” : 2, “domainName” : “test2.com”, “hosting” : “aws.amazon.com”} { “_id” : …

Read more

Maven + Emma code coverage example

Emma is a free Java code coverage tool. In this tutorial, we will show you how to use Maven to generate the Emma code coverage report for your project, and also how to integrate the Emma report into the Maven project site. 1. Generate Emma Code Coverage Report Do nothing, just type the following Maven …

Read more

Maven site build is very slow – dependency report

Creating a Maven site, but the build is very slow to generate the dependency report. C:\mkyong_projects\>mvn site [INFO] Scanning for projects… [INFO] [INFO] ————————————– [INFO] Building Maven Webapp 1.0-SNAPSHOT [INFO] ————————————– [INFO] //… [INFO] Generating "Project License" report [INFO] Generating "Project Team" report [INFO] Generating "Project Summary" report [INFO] Generating "Dependencies" report //…… Hanging here… …

Read more

Emma – Class x appears to be instrumented already

Review the “maven-emma-plugin” in pom.xml : pom.xml <project> //… <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0-alpha-3</version> <inherited>true</inherited> <executions> <execution> <phase>process-classes</phase> <goals> <goal>instrument</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <inherited>true</inherited> <configuration> <forkMode>once</forkMode> <reportFormat>xml</reportFormat> <classesDirectory> ${project.build.directory}/generated-classes/emma/classes </classesDirectory> </configuration> </plugin> </plugins> </build> </project> 1. Problem When I run the command mvn emma:emma to generate the code coverage report, …

Read more

The type DefaultHttpClient is deprecated

Eclipse IDE prompts warning on new DefaultHttpClient, mark this class as deprecated. package com.mkyong.web.controller; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; public class WebCrawler { public static void main(String[] args) throws Exception { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("https://mkyong.com"); HttpResponse response = client.execute(request); //… } } Solution Dive …

Read more

Java – Check if web request is from Google crawler

If a web request is coming from Google crawler or Google bot, the requested “user agent” should look similar like this : Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) or (rarely used): Googlebot/2.1 (+http://www.google.com/bot.html) Source : Google crawlers 1. Java Example In Java, you can get the “user agent” from HttpServletRequest. Example : Service hosted at abcdefg.com @Autowired …

Read more

How To Get HTTP Request Header In Java

This example shows you how to get the HTTP request headers in Java. To get the HTTP request headers, you need this class HttpServletRequest : 1. HttpServletRequest Examples 1.1 Loop over the request header’s name and print out its value. WebUtils.java package com.mkyong.web.utils; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; public class WebUtils { …

Read more

Donate to Charity

If you like my works and tutorials on “mkyong.com”, please consider making a donation of $10 or whatever you can to protect and sustain the following charities : Thanks. 1. Doctors Without Borders The Doctors Without Borders works in nearly 70 countries providing medical aid to those most in need regardless of their race, religion, …

Read more

Java Custom Annotations Example

In this tutorial, we will show you how to create two custom annotations – @Test and @TestInfo, to simulate a simple unit test framework. P.S This unit test example is inspired by this official Java annotation article. 1. @Test Annotation This @interface tells Java this is a custom annotation. Later, you can annotate it on …

Read more

TestNG Hello World Example

A classic example, show you how to get started with TestNG unit test framework. Tools used : TestNG 6.8.7 Maven 3 Eclipse IDE 1. TestNG Dependency Add TestNG library in the pom.xml. pom.xml <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8.7</version> <scope>test</scope> </dependency> 2. TestNG Example Review a simple class, has a method to return a fixed email “[email protected]”. …

Read more