Skip to content

optionfactory/defiance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Defiance

Replace @EnableWebMvc annotation with @EnableWebMvcWithDirectFieldAccess to activate direct field access in Spring WebDataBinder.

This allows binding between requests and DTOs with public fields and without getters and setters.

NOTE: do not use both @EnableWebMvc and @EnableWebMvcWithDirectFieldAccess on the same context.

Example

@Configuration
//@EnableWebMcv
@EnableWebMvcWithDirectFieldAccess
public class ApiConfig extends WebMvcConfigurerAdapter {

    // configuration

}

public class WebApp implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext sc) throws ServletException {

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(MainConfig.class);
        sc.addListener(new ContextLoaderListener(rootContext));

        final AnnotationConfigWebApplicationContext apiContext = new AnnotationConfigWebApplicationContext();
        apiContext.setParent(rootContext);
        apiContext.setDisplayName("apiContext");
        apiContext.register(ApiConfig.class);
        final ServletRegistration.Dynamic api = sc.addServlet("api", new DispatcherServlet(apiContext));
        api.setLoadOnStartup(1);
        api.addMapping(... mappings ...);
    }
}

Maven artifact

<dependency>
  <groupId>net.optionfactory</groupId>
  <artifactId>defiance</artifactId>
  <version>1.0</version>
</dependency>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages