Autowiring in servlet

I followed the solution in the following link, and it works fine: Access Spring beans from a servlet in JBoss public class MyServlet extends HttpServlet { @Autowired private MyService myService; public void init(ServletConfig config) { super.init(config); SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); } }

Why BCryptPasswordEncoder from Spring generate different outputs for same input?

public static void main(String[] args) { // spring 4.0.0 org.springframework.security.crypto.password.PasswordEncoder encoder = new org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder(); // $2a$10$lB6/PKg2/JC4XgdMDXyjs.dLC9jFNAuuNbFkL9udcXe/EBjxSyqxW // true // $2a$10$KbQiHKTa1WIsQFTQWQKCiujoTJJB7MCMSaSgG/imVkKRicMPwgN5i // true // $2a$10$5WfW4uxVb4SIdzcTJI9U7eU4ZwaocrvP.2CKkWJkBDKz1dmCh50J2 // true // $2a$10$0wR/6uaPxU7kGyUIsx/JS.krbAA9429fwsuCyTlEFJG54HgdR10nK // true // $2a$10$gfmnyiTlf8MDmwG7oqKJG.W8rrag8jt6dNW.31ukgr0.quwGujUuO // true for (int i = 0; i < 5; i++) { // “123456” – plain text – user input from user interface … Read more

How to unit test a Spring MVC controller using @PathVariable?

I’d call what you’re after an integration test based on the terminology in the Spring reference manual. How about doing something like: import static org.springframework.test.web.ModelAndViewAssert.*; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({/* include live config here e.g. “file:web/WEB-INF/application-context.xml”, “file:web/WEB-INF/dispatcher-servlet.xml” */}) public class MyControllerIntegrationTest { @Inject private ApplicationContext applicationContext; private MockHttpServletRequest request; private MockHttpServletResponse response; private HandlerAdapter handlerAdapter; private MyController controller; … Read more

Is there a static way to get the current HttpServletRequest in Spring

If you are using spring you can do the following: public static HttpServletRequest getCurrentHttpRequest(){ RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); if (requestAttributes instanceof ServletRequestAttributes) { HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest(); return request; } logger.debug(“Not called in the context of an HTTP request”); return null; }

Is it possible to have multiple PropertyPlaceHolderConfigurer in my applicationContext?

Yes you can do more than one. Be sure to set ignoreUnresolvablePlaceholders so that the first will ignore any placeholders that it can’t resolve. <bean id=”ppConfig1″ class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”> <property name=”ignoreUnresolvablePlaceholders” value=”true”/> <property name=”locations”> <list> <value>classpath*:/my.properties</value> </list> </property> </bean> <bean id=”ppConfig2″ class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”> <property name=”ignoreUnresolvablePlaceholders” value=”false”/> <property name=”locations”> <list> <value>classpath*:/myOther.properties</value> </list> </property> </bean> Depending on your application, you … Read more