My intent is to plug in the spring 4 websocket classes for my existing project. Here is the spring websocket project link: https://github.com/rstoyanchev/spring-websocket-test
problem is my project is using xml configuration files while the websocket project is using very odd java file configurations.
My question is is there a way to import these configurations files from the spring project into my already existing (xml based) project?
for example, my xmls are being refereed in the web.xml, while in the spring websocket project there is no web.xml at all..
P.S Not all configuration classes in that project are components, here are 2 classes without @Configuration anotations:
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { WebSecurityConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class, WebSocketConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected void customizeRegistration(Dynamic registration) {
registration.setInitParameter("dispatchOptionsRequest", "true");
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
}
}
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable() //TODO Refactor login form
.authorizeRequests()
.antMatchers("/assets/**").permitAll()
.anyRequest().authenticated()
.and()
.logout()
.logoutSuccessUrl("/login.html?logout")
.logoutUrl("/logout.html")
.permitAll()
.and()
.formLogin()
.defaultSuccessUrl("/index.html")
.loginPage("/login.html")
.failureUrl("/login.html?error")
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("fabrice").password("fab123").roles("USER").and()
.withUser("paulson").password("bond").roles("ADMIN","USER");
}
So will they be picked up in my original scan? how should i integrate them then??
Thanks!
Spring 4 is now released, so you can simply include it as a dependency in your project: http://search.maven.org/#artifactdetails%7Corg.springframework%7Cspring-framework-bom%7C4.0.0.RELEASE%7Cpom
I have written a detailed tutorial/example on how to use Spring 4 WebSockets with Spring Security 3.2 to 'retro-fit' a regular Spring MVC application with WebSockets. Click here