Merge pull request #462 from vpavic/gh-457

Update WebSocket sample to use H2 console auto-configuration
This commit is contained in:
Rob Winch
2016-04-04 07:34:09 -05:00
4 changed files with 12 additions and 43 deletions

View File

@@ -1,41 +0,0 @@
/*
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.config;
import org.h2.server.web.WebServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Initializes the H2 {@link WebServlet} so we can access our in memory database from the
* URL "/h2".
*
* @author Rob Winch
*/
@Configuration
public class H2Initializer {
@Bean
public ServletRegistrationBean h2Servlet() {
ServletRegistrationBean servletBean = new ServletRegistrationBean();
servletBean.addUrlMappings("/h2/*");
servletBean.setServlet(new WebServlet());
return servletBean;
}
}

View File

@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -51,6 +52,14 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
}
// @formatter:on
// @formatter:off
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring().antMatchers("/h2-console/**");
}
// @formatter:on
// @formatter:off
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth, UserDetailsService userDetailsService) throws Exception {

View File

@@ -1,2 +1,3 @@
spring.thymeleaf.cache=false
spring.template.cache=false
spring.h2.console.enabled=true

View File

@@ -93,7 +93,7 @@
</div>
<ul class="nav">
<li><a th:href="@{/}">IM</a></li>
<li><a th:href="@{/h2/}">H2</a></li>
<li><a th:href="@{/h2-console/}">H2</a></li>
</ul>
</div>
@@ -121,4 +121,4 @@
</div>
</div>
</body>
</html>
</html>