net.optionfactory:defiance

Enable Spring Web MVC with public fields binding support

License

License

Categories

Categories

Net
GroupId

GroupId

net.optionfactory
ArtifactId

ArtifactId

defiance
Last Version

Last Version

2.0
Release Date

Release Date

Type

Type

jar
Description

Description

net.optionfactory:defiance
Enable Spring Web MVC with public fields binding support
Project URL

Project URL

https://github.com/optionfactory/defiance
Source Code Management

Source Code Management

https://github.com/optionfactory/defiance

Download defiance

How to add to project

<!-- https://jarcasting.com/artifacts/net.optionfactory/defiance/ -->
<dependency>
    <groupId>net.optionfactory</groupId>
    <artifactId>defiance</artifactId>
    <version>2.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.optionfactory/defiance/
implementation 'net.optionfactory:defiance:2.0'
// https://jarcasting.com/artifacts/net.optionfactory/defiance/
implementation ("net.optionfactory:defiance:2.0")
'net.optionfactory:defiance:jar:2.0'
<dependency org="net.optionfactory" name="defiance" rev="2.0">
  <artifact name="defiance" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.optionfactory', module='defiance', version='2.0')
)
libraryDependencies += "net.optionfactory" % "defiance" % "2.0"
[net.optionfactory/defiance "2.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.springframework : spring-webmvc jar 5.1.5.RELEASE

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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>
net.optionfactory

OptionFactory

Versions

Version
2.0
1.0