Skip to content

Instantly share code, notes, and snippets.

View keesun's full-sized avatar
📺
On Air

Keesun Baik (a.k.a, Whiteship) keesun

📺
On Air
View GitHub Profile
@keesun
keesun / WebAppInitializer.java
Created November 24, 2011 05:10
Spring 3.1's MVC Web Application Initializer
public class WebAppIntializer implements WebApplicationInitializer {
 
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        //parent
        AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(AppConfig.class);
 
        servletContext.addListener(new ContextLoaderListener(rootContext));
//        new ContextLoader(rootContext).initWebApplicationContext(servletContext);
@keesun
keesun / AppConfig.java
Created November 24, 2011 08:55
Spring 3.1 Application Configuration
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "whiteship", excludeFilters = {@ComponentScan.Filter(Configuration.class), @ComponentScan.Filter(Controller.class)})
public class AppConfig {
@Bean(destroyMethod = "shutdown")
public DataSource dataSource(){
return new EmbeddedDatabaseBuilder()
.setName("bookDB")
.setType(EmbeddedDatabaseType.H2)
@keesun
keesun / WebConfig.java
Created November 24, 2011 08:57
Spring 3.1 Web Application Configuration
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "whiteship",
useDefaultFilters = false,
includeFilters = @ComponentScan.Filter(Controller.class))
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
@keesun
keesun / pom.xml
Created January 12, 2012 23:49
Dependencies for Servlet 3.0
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
@keesun
keesun / TestServlet.java
Created January 12, 2012 23:51
Servlet 3.0's Annotation based Servlet registration sample
@WebServlet(urlPatterns = "/test")
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType(MediaType.TEXT_PLAIN_VALUE);
PrintWriter out = res.getWriter();
out.write("Hello");
out.close();
}
@keesun
keesun / SpringServlet.java
Created January 12, 2012 23:53
Restration of Spring DispatcherServlet with Servlet 3.0's annotation
@WebServlet(urlPatterns = "/spring/*",
initParams = {
@WebInitParam(name = "contextConfigLocation", value = "classpath*:/spring.xml")})
public class SpringServlet extends DispatcherServlet {
}
@keesun
keesun / FileUploadServlet.java
Created January 13, 2012 03:19
Servlet 3.0's FileUpload Sample
@WebServlet("/upload")
@MultipartConfig(location = "/tmp")
public class FileUploadServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
getServletContext().getRequestDispatcher("/WEB-INF/views/fileUpload.jsp").forward(req, res);
}
@Override
@keesun
keesun / AsyncServlet.java
Created January 16, 2012 16:32
Servlet 3.0's Asynchronous Support sample
package me.whiteship.board.modules.servlet.async;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@keesun
keesun / AppConfig.java
Created January 18, 2012 13:36
Spring 3.1's TestContext
package sandbox.testcontext.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Keesun Baik
*/
@Configuration
public class AppConfig {
@keesun
keesun / AppConfig.java
Created January 18, 2012 13:57
Spring 3.1's extends @configuration
@Configuration
public class AppConfig extends HelloConfig {
@Override
public Hello hello() {
Hello h = super.hello();
h.setName("Keesun");
return h;
}
}