Category Archives: Spring

Spring Annotation Based Single Class Web Application with JSP View Resolver

Works on Servlet 3.0+ containers. Better not mix Configuration classes with Controller classes. It is only for simplicity import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration;   import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView;   @Configuration @EnableWebMvc @Controller public class [...]

Also posted in Java, jetty | Leave a comment

Spring Annotation Based Single Class Web Application

Works on Servlet 3.0+ containers. Better not mix Configuration classes with Controller classes. It is only for simplicity import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration;   import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Controller; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.config.annotation.EnableWebMvc;   @Configuration @EnableWebMvc @Controller public class SpringWebApp implements WebApplicationInitializer {   @RequestMapping("/") @ResponseBody public [...]

Also posted in Java | Leave a comment

GWT 2.4 + Spring MVC 3.0

GWT 2.4 + Spring MVC 3.0 (+ Hibernate) – Poniżej kilka podejść i ich przykładowe implementacje gotowe do użycia. 1. Metoda najmniej inwazyjna – wg mnie najlepsza https://github.com/marioosh-net/gwt-spring-non-invasive 2. Metoda z wykorzystaniem klasy która jednocześnie funkcjonuje jako RemoteServiceServlet i Spring MVC Controller https://github.com/marioosh-net/gwt-spring 3. Przy użyciu: GWT Server Library https://github.com/marioosh-net/gwt-spring-sl

Also posted in Java | Leave a comment

Spring: Spring Security + reCaptcha

Może niezbyt eleganckie rozwiązanie, ale działa. Przedstawione rozwiązanie jest oparte na Spring Web Flow + JSF 2.0. Na wejsciu do strony logowania generowany jest kod html reCaptcha. Tutaj fragment konfiguracji flow’a: 1 2 3 4 5 6 7 <view-state id="login"> <on-render> <evaluate expression="reCaptcha.createRecaptchaHtml(null,null)" result="flowScope.captcha"/> </on-render> <transition on="login"/> <transition on="resetpass" to="resetpassword"/> </view-state> Tworzymy beana springowego dla [...]

Also posted in Java | Tagged , , | Leave a comment

Spring: Upload pliku w Spring Web Flow

xhtml: 1 2 3 4 <h:form enctype="multipart/form-data"> <input type="file" name="file" /> <h:commandButton action="upload" value="Ok" /> </h:form> beans.xml: 1 2 3 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="100000"/> </bean> flow.xml: 1 2 3 4 5 6 7 8 9 10 11 <var name="uploadBean" class="beans.UploadBean"/> <view-state id="upload"> <transition on="upload" to="upload-action"/> </view-state> <action-state id="upload-action"> <evaluate expression="uploadBean.upload(flowRequestContext)"/> <transition on="success" to="upload"> [...]

Also posted in Java | Tagged , | 2 Comments

Springowa usługa email (na koncie Gmail)

Konfiguracja Springowego “wysyłacza maili”: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="smtp.gmail.com" /> <property name="username" value="xxx@gmail.com" /> <property name="password" value="xxx" /> <property name="port" value="587" /> <property name="javaMailProperties"> <props> <prop key="mail.smtp.from">xxx@gmail.com</prop> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> <prop key="mail.debug">true</prop> </props> </property> </bean> [...]

Posted in Spring | Tagged | Leave a comment