Created
September 9, 2017 23:15
-
-
Save Deviad/9d606040e869a151b267a63694f8d9bd to your computer and use it in GitHub Desktop.
Test with EnableLoadTimeWeaving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.davidepugliese.springfood; | |
import org.hibernate.SessionFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.web.servlet.FilterRegistrationBean; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.EnableLoadTimeWeaving; | |
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean; | |
import org.springframework.web.servlet.config.annotation.CorsRegistry; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |
import javax.persistence.EntityManagerFactory; | |
@EnableLoadTimeWeaving | |
@Configuration | |
// @ComponentScan("com.luv2code.springdemo") | |
public class WebConfig { | |
@Autowired | |
private EntityManagerFactory entityManagerFactory; | |
@Bean | |
public SessionFactory getSessionFactory() { | |
if (entityManagerFactory.unwrap(SessionFactory.class) == null) { | |
throw new NullPointerException("factory is not a hibernate factory"); | |
} | |
return entityManagerFactory.unwrap(SessionFactory.class); | |
} | |
@Bean | |
public WebMvcConfigurer corsConfigurer() { | |
return new WebMvcConfigurerAdapter() { | |
@Override | |
public void addCorsMappings(CorsRegistry registry) { | |
registry.addMapping("/api/**") | |
.allowedOrigins("*") | |
.allowedMethods("POST", "GET", "PATCH", "PUT", "DELETE") | |
.allowedHeaders("header1", "header2", "header3") | |
.exposedHeaders("header1", "header2") | |
.allowCredentials(false).maxAge(0); | |
} | |
}; | |
} | |
@Bean | |
public FilterRegistrationBean jwtFilter() { | |
final FilterRegistrationBean registrationBean = new FilterRegistrationBean(); | |
registrationBean.setFilter(new JwtFilter()); | |
registrationBean.addUrlPatterns("/secure/*"); | |
return registrationBean; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment