Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated Spring Boot and removed WEB-INF XML files
- Loading branch information
Showing
9 changed files
with
133 additions
and
87 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/raibledesigns/boot/config/ApplicationInitializer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.raibledesigns.boot.config; | ||
|
||
import org.glassfish.jersey.servlet.ServletContainer; | ||
import org.glassfish.jersey.servlet.ServletProperties; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.context.embedded.ServletRegistrationBean; | ||
import org.springframework.boot.web.SpringBootServletInitializer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableAutoConfiguration | ||
@ComponentScan | ||
public class ApplicationInitializer extends SpringBootServletInitializer { | ||
|
||
@Bean | ||
public ServletRegistrationBean jerseyServlet() { | ||
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/"); | ||
registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyConfig.class.getName()); | ||
return registration; | ||
} | ||
|
||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
return application.sources(ApplicationInitializer.class); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ApplicationInitializer.class, args); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/raibledesigns/boot/config/JerseyConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.raibledesigns.boot.config; | ||
|
||
import org.glassfish.jersey.filter.LoggingFilter; | ||
import org.glassfish.jersey.jackson.JacksonFeature; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.server.ServerProperties; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
|
||
@ApplicationPath("/v1.0") | ||
public class JerseyConfig extends ResourceConfig { | ||
|
||
public JerseyConfig() { | ||
packages("com.raibledesigns.boot.service"); | ||
property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); | ||
property(ServerProperties.JSON_PROCESSING_FEATURE_DISABLE, false); | ||
property(ServerProperties.MOXY_JSON_FEATURE_DISABLE, true); | ||
property(ServerProperties.WADL_FEATURE_DISABLE, true); | ||
register(LoggingFilter.class); | ||
register(JacksonFeature.class); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/raibledesigns/boot/config/MvcConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.raibledesigns.boot.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
@Configuration | ||
public class MvcConfig extends WebMvcConfigurerAdapter { | ||
|
||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
registry.addViewController("/").setViewName("index"); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/raibledesigns/boot/config/WebSecurityConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.raibledesigns.boot.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@Order(Ordered.LOWEST_PRECEDENCE - 6) | ||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.authorizeRequests() | ||
.antMatchers("/", "/home").permitAll() | ||
.antMatchers("/rest/**").hasRole("USER") | ||
.anyRequest().authenticated(); | ||
http.httpBasic().realmName("My API"); | ||
} | ||
|
||
@Override | ||
protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception { | ||
authManagerBuilder.inMemoryAuthentication() | ||
.withUser("test").password("test123").roles("USER"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<include resource="org/springframework/boot/logging/logback/base.xml"/> | ||
<logger name="org.springframework.boot" level="INFO"/> | ||
<logger name="org.springframework.security" level="ERROR"/> | ||
</configuration> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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