spring annotation inheritance

@Autowired/@Inject (method) When you use @Inherited on a class annotation, this means that when that annotation is queried on a non-annotated subclass, the Java will look for it in the superclass. When you use @Inherited on a method annotation, this means that when that annotation is queried on a non-annotated method overridden in subclass, Java…

Converting Strings to Number in Javascript: Pitfalls

There are many ways to convert a String to a Number. I can think of at least 5 ways to convert a string into a number! parseInt(num); // default way (no radix) parseInt(num, 10); // parseInt with radix (decimal) parseFloat(num) // floating point Number(num); // Number constructor ~~num //bitwise not num / 1 // diving…

hibernate entitymanager spring BeanDefinitionStoreException FactoryConfigurationError DocumentBuilderFactory cannot be found

When we try to upgrade spring jpa/hibernate from 3 to 4. One of our standalone jar using spring has error when loading application context: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring/application-context-xxx.xml]; nested exception is javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found   After searching around, it turns out the┬áhibernate-entitymanager 4.3.11 has a…

SSH login without password using SSH public/private keys

SSH or Secure SHELL is the most popular and trusted UNIX-based cryptographic network protocol. It can be used for secure data communication, remote server logins, remote command execution, and many other secure network services between two networked servers. Normally, password authentication is used to connect to a remote server via SSH. In this blog tutorial…

enum vs public static final

Technically one could indeed view enums as a class with a bunch of typed constants, and this is in fact how enum constants are implemented internally. Using an enum however gives you useful methods (Enum javadoc) that you would otherwise have to implement yourself, such as Enum.valueOf. There is also .values() to iterate over the…

spring IoC life cycle

Spring IoC Initialization Life-cycle This is briefly enumerated: 1. Read and parse the Bean definitions (either as XML, JavaConfig) 2. Process BeanFactoryPostProcessors 3. Construct bean by calling its constructor 4. Call setters, dependencies injected 5. Inject the required beans as defined by the *Aware Interfaces 6. Call postProcessBeforeIntialization 7. Call the initializaion callbacks.(like InitializingBean’s afterPropertiesSet…

@Qualifier not working after upgrade from Spring3 to Spring4

We have struts 1.x used with Spring 3.x in our project. In the process of upgrading from spring 3->4, our qualifier annotation in the struts action does not work any more. After digging in and compare the Spring 3 and 4, finally found the reason. 1.QualifierAnnotationAutowireCandidateResolver is not the default resolver in spring 4 In…

How does Spring @Transactional Really Work?

In this post we will do a deep dive into Spring transaction management. We will go over on how does @Transactional really works under the hood. Other upcoming posts will include: how to use features like propagation and isolation what are the main pitfalls and how to avoid them Database For a db transaction, it…

$scope.$evalAsync() vs. $timeout() In AngularJS

Sometimes, in an AngularJS application, you have to explicitly tell AngularJS when to initiate it’s $digest() lifecycle (for dirty-data checking). This requirement is typically contained within a Directive; but, it may also be in an asynchronous Service. Most of the time, this can be easily accomplished with the $scope.$apply() method. However, some of the time,…

form submit on enter when one input text

Got an odd behavior today when dealing with a form which has only one input. The input binds to a js function to judge if it is key==13, we do tweak the input params and submit. However everytime we hit enter, even before executing the js function, the form has already been submitted to the…