The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

akuma8 (15) [Avatar] Offline
#1
Hi Craig,

I bought the book and I am reading chapter 2 but it seems like the class WebMvcConfigurerAdapter is deprecated. My Maven's parent version is 2.0.0.M3.

Also could you provide a way of how testing this code, above all the posts methods? How to test JSR 303 validation with Spring?

Thanks a lot.
habuma (279) [Avatar] Offline
#2
akuma8 wrote:Hi Craig,

I bought the book and I am reading chapter 2 but it seems like the class WebMvcConfigurerAdapter is deprecated. My Maven's parent version is 2.0.0.M3.

Also could you provide a way of how testing this code, above all the posts methods? How to test JSR 303 validation with Spring?

Thanks a lot.


Yes, regarding WebMvcConfigurerAdapter...since the MEAP was pushed, I learned that that particular class has gone away in favor of Java 8 default methods in WebMvcConfigurer. I need to update the example, for sure...in the meantime, suffice it to say that instead of extending WebMvcConfigurerAdapter, you can implement WebMvcConfigurer and override the methods the same way.
akuma8 (15) [Avatar] Offline
#3
I extended "WebMvcConfigurationSupport" which is the equivalent in Spring 5.
483055 (1) [Avatar] Offline
#4
I did it this way:

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
WebMvcConfigurer.super.addViewControllers(registry);
registry.addViewController("/").setViewName("home");
}

}

and it is working like a charm
581524 (1) [Avatar] Offline
#5
483055 wrote:I did it this way:

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
WebMvcConfigurer.super.addViewControllers(registry);
registry.addViewController("/").setViewName("home");
}

}

and it is working like a charm


The following code also works.

package readinglist;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//WebMvcConfigurer.super.addViewControllers(registry);
//registry.addViewController("/").setViewName("home");
registry.addRedirectViewController("/", "/readingList");
}
}