Monthly Archives: January 2012

@Autowired

after thinking a lot about DIP, it was kinda clear, that we need to refactor some stuff… ok not really the thinking part, more the discusting part… a big beans.xml file sucks… and analysing my beanx.xml showed, that one small component is used everywhere and a lot of injects only where this one class…

first, something about a concept… in my opinion there are two ways for dependency injection… the one where a config file injects classes to others and the one where the class, wishes to get an injection… secondly is @Resource, @Autowired…

and in my project, i thought the one class, which is used almost everywhere should be get by @Autowired… and actually it was an static class, where the key-value configuration out of the db is loaded… so simply refactored it…

and the main problem was: tell spring, that it should autowire!

<context:annotation-config />
<context:component-scan base-package=“[class name]” />

after adding this few lines to the beans.xml, it actually found the [class name] in time and could inject it 🙂

crap config!

powermock

PowerMock is an extension for Mockito or EasyMock, which can mock really special things… static classes, Constructors, partial mocks,…

cool thing…. http://code.google.com/p/powermock/

read from classpath

in our project we have a few templates… so the biggest question is, where to put them… there are a lot of simple answers, but consider this: 4 productive instances, 2 test and 1 dev… these platforms dont know each others… so the solution database, which they share, or localy on each machine… db is not a solution, because the main user has no access to it, and changing templates might happen at the beginning… so file system it is… and we dicided to put them in classpath… easier to roll out for the devs… so how access a file from the classpath?

String filenameOnClasspath = “/myfile.txt” // Located in a directory which is on the classpath
URL url = getClass().getResource(filename);
String fullyQualifiedFilename = url.getFile();

Source