Elric has added a new
Spring Mock certification Practice test for our readers . The questions are close to the real exam and will help you in practicing for the test or to test your Spring proficiency
Test Details : 50 questions, 88 minutes to complete and a minimal score of 76% to reach (38 right questions)
Repartition of the questions by category:
- Container (13)
- Test (5)
- AOP (10)
- Data Access (5)
- Transactions (5)
- Spring MVC (3)
- Spring Security (3)
- Remoting (2)
- JMS (2)
- JMX (2)
Please take the test and give your feedback to Elric. Thanks to Elric for taking out time to create the test and share with the community
After huge success of last two Spring mock tests from ikoko, Jacek has added another test for our readers .
Spring 3.x certification mock test
Questions very similar to originals with almost the same difficulty level. Majority questions are from most important sections at exam: container, testing, AOP, transactions. Only few from other sections like MVC, REST, JMX, JMS.
This is a 30 question practice test. 5 questions are free for you to try.
It is very reasonably priced at $1.99.
If you buy all there tests, you would save on paypal fees.
I am sure you would like the test. Jacek is looking for feedback and inputs to make the test better.
There are multiple ways to read properties file in Spring
Let us say you have database user name , password etc configured in jdbc.properties and would like to inject the values at run time.
Here is what will go in applicationContext.xml
<bean id=”propertyConfigurer”>
<property name=”locations”>
<list>
<value>classpath:environment.properties.properties</value>
</list>
</property>
</bean>
<bean id=”dataSource” destroy-method=”close”>
<property name=”driverClass” value=”${jdbc.driverClass}”/>
<property name=”jdbcUrl” value=”${jdbc.url}”/>
<property name=”user” value=”${jdbc.user}”/>
<property name=”password” value=”${jdbc.password}”/>
<property name=”minPoolSize” value=”${jdbc.minPoolSize}”/>
<property name=”maxPoolSize” value=”${jdbc.maxPoolSize}”/>
</bean>
and this will be your properties file
jdbc.driverClass=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@abc.com:1521:ORAC
jdbc.user=hello
jdbc.password=hello
jdbc.minPoolSize=1
jdbc.maxPoolSize=10
At run time, the properties file value will be injected into the applicationContext.xml
In hibernate if you set this in you code
session.setFlushMode(FlushMode.NEVER)
What does it signify ?
It means that the Hibernate session not to flush any state changes to database unless flush() is explicitly called by the application.
When setting the FlushMode.NEVER , will it improve the performance and reduce the run time ?
It would not affect if you are running a single update or a series of small updates. It really affects you when you are doing batch processing. The reason for this is the way hibernate implements dirty checking. Once you load an object in memory and do not evict it, the hibernate session keeps track of it in case if it was changed. So, any time you perform a query, the session iterates over all objects in the session checking dirtiness and flushes any dirty objects to the database. It does this to ensure that all state changes that might affect the query are present in the database before issuing the query to it. That’s fine when you have only a few objects in session, but when you have thousands and are performing thousands of queries, it becomes a real drain on performance.
Tim fennel has made this interesting observation about the FlushMode.NEVER in his blog here.
Spring provides a similar way to annotate methods @Transactional(readOnly=true) in Spring which internally has the same affect.
For users who have been taking the Spring certification practice tests 1 and Spring certification practice tests 2 at skill-guru have raise the concern that
We have contacted the creator of these tests Ikoko , and he has clarified thatthe Spring documentation for the exam syllabus has changed (improved) since he had created the exam so the tests now appear to be different to the syllabus
The historical documentation and support for the certification has been poor from Spring and might even be incorrect.
he also pointed out that Skill-guru test-takers basing their opinions on the Spring documentation and not actually doing the Spring exam are therefore possibly misled by the official documentation
From Ikoko’s email
I sat both the 2.5 exam and 3.0 exam so have experienced both exams first-hand and have been keen to keep my exams accurate based on real exam-experience and not any vague syllabus published by Spring
Having said all, this at a higher topic level I only noticed the category of SpEL (Spring expression language) being a category in my tests that was not in the offical syllabus. I had 1 SpEL question in test 1, and 2 questions in test 2. I have now removed all three questions.
Hope this clarifies the doubt of our readers and thanks to MaggieL and Shane Mannion for pointing this out
This post explain how to use Spring JDBCTemplate to do batch insert and update.
If you are using SimpleJDBCtemplate then the Spirng docs are good place to find a good explanation for it Simple JDBC Template
If you are using JDBCtemplate , here is the example to use prepared statements and do batch updates
public boolean createGroceyList(List<Grocery> groceryList){
final List<Grocery> aGroceryList = groceryList
int result[] = this.jdbcTemplate.batchUpdate(
“the query goes here “,new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setLong(1, “param 1 goes here “);
ps.setString(2, “param 2 goes here “);
ps.setString(3, “param 3 goes here “);
}
public int getBatchSize() {
return aGroceryList.size();
}
});
return (aGroceryList.size() == result.length ? true : false);
}
The query would be something similar to
INSERT INTO GROCERY(ID, NAME, QUANTITY) VALUES(?,?,?)
If you are doing integration testing with your spring environment, you would like to see an end to end test running rather than just simple Junit tests. Unit testing are important but there are occasions in which we really the tire to hit the road and what is really happening with the system
During test, if you may want to set up up test data or some fields like connection pool only once. If you are using simple JUnit tests , then an easy way would be to annotate your methods with @BeforeClass and @AfterClass. Here is an example of @BeforeClass and @AfterClass
How do you achieve the functionality of @BeforeClass in Spring ?
Now let us say you want to run Spring integration tests and your class is
public class MySpringIntegrationTest extends AbstractDependencyInjectionSpringContextTests {
private static int ID = 1111;
@Autowired
private MyBean myBean;
@BeforeClass
public static void before() {
// all the set up code will come here. for eg connecting to database
}
}
If you run this class, @BeforeClass will never run.
Reason is that spring’s test classes are base[code]]czoyNjpcImQgb24gSnVuaXQgMy54IGZyYW1ld29yay4gXCI7e1smKiZdfQ==[[/code]@BeforeClass has been introduced with JUnit4. Since your class extends AbstractDependencyInjectionSpringContextTests, Junit 4 functions are never invoked.
You will not see compile time errors because Junit 4 would be in your IDE or project classpath.
How to run Spring tests cases with Junit4 ? Read more…
In our last post , we had talked about Create your first REST service using JERSEY.
There are situations in which you would like your Spring services as web services. In this link below there is a code example of both REST and SOAP access the same backbone. Here is the link