File tree Expand file tree Collapse file tree
spring-security-rest-custom Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<beansProjectDescription >
33 <version >1</version >
4- <pluginVersion ><![CDATA[ 3.3 .0.201307091516 -RELEASE]]> </pluginVersion >
4+ <pluginVersion ><![CDATA[ 3.4 .0.201310051539 -RELEASE]]> </pluginVersion >
55 <configSuffixes >
66 <configSuffix ><![CDATA[ xml]]> </configSuffix >
77 </configSuffixes >
88 <enableImports ><![CDATA[ false]]> </enableImports >
99 <configs >
10- <config >src/main/webapp/WEB-INF/api-servlet.xml</config >
1110 </configs >
1211 <configSets >
1312 </configSets >
Original file line number Diff line number Diff line change 22
33import java .util .Set ;
44
5+ import javax .servlet .FilterRegistration .Dynamic ;
56import javax .servlet .ServletContext ;
67import javax .servlet .ServletException ;
78import javax .servlet .ServletRegistration ;
89
910import org .springframework .web .WebApplicationInitializer ;
1011import org .springframework .web .context .ContextLoaderListener ;
1112import org .springframework .web .context .support .AnnotationConfigWebApplicationContext ;
13+ import org .springframework .web .filter .DelegatingFilterProxy ;
1214import org .springframework .web .servlet .DispatcherServlet ;
1315
1416public class MainWebAppInitializer implements WebApplicationInitializer {
@@ -43,6 +45,11 @@ public void onStartup(final ServletContext sc) throws ServletException {
4345 if (!mappingConflicts .isEmpty ()) {
4446 throw new IllegalStateException ("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278" );
4547 }
48+
49+ // spring security filter
50+ final DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy ("springSecurityFilterChain" );
51+ final Dynamic addedFilter = sc .addFilter ("springSecurityFilterChain" , springSecurityFilterChain );
52+ addedFilter .addMappingForUrlPatterns (null , false , "/*" );
4653 }
4754
4855}
Original file line number Diff line number Diff line change 22
33import java .util .List ;
44
5+ import org .springframework .context .annotation .Bean ;
56import org .springframework .context .annotation .ComponentScan ;
67import org .springframework .context .annotation .Configuration ;
8+ import org .springframework .context .support .PropertySourcesPlaceholderConfigurer ;
79import org .springframework .http .converter .HttpMessageConverter ;
810import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
911import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
1214@ Configuration
1315@ EnableWebMvc
1416@ ComponentScan ("org.baeldung.web" )
17+ // @ImportResource({ "classpath:prop.xml" })
18+ // @PropertySource("classpath:foo.properties")
1519public class WebConfig extends WebMvcConfigurerAdapter {
1620
1721 public WebConfig () {
@@ -26,6 +30,13 @@ public void configureMessageConverters(final List<HttpMessageConverter<?>> conve
2630 converters .add (new MappingJackson2HttpMessageConverter ());
2731 }
2832
29- //
33+ // beans
34+
35+ @ Bean
36+ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer () {
37+ final PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer ();
38+ ppc .setIgnoreUnresolvablePlaceholders (true );
39+ return ppc ;
40+ }
3041
3142}
Original file line number Diff line number Diff line change 11package org .baeldung .config .parent ;
22
3+ import org .springframework .context .annotation .Bean ;
34import org .springframework .context .annotation .ComponentScan ;
45import org .springframework .context .annotation .Configuration ;
6+ import org .springframework .context .annotation .PropertySource ;
7+ import org .springframework .context .support .PropertySourcesPlaceholderConfigurer ;
58
69@ Configuration
710@ ComponentScan ("org.baeldung.service" )
11+ // @ImportResource({ "classpath:prop.xml" })
12+ @ PropertySource ("classpath:foo.properties" )
813public class ServiceConfig {
914
1015 public ServiceConfig () {
1116 super ();
1217 }
1318
19+ // beans
20+
21+ @ Bean
22+ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer () {
23+ final PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer ();
24+ ppc .setIgnoreUnresolvablePlaceholders (true );
25+ return ppc ;
26+ }
27+
1428}
Original file line number Diff line number Diff line change 11package org .baeldung .service ;
22
33import org .baeldung .web .dto .Foo ;
4+ import org .springframework .beans .factory .InitializingBean ;
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .beans .factory .annotation .Value ;
7+ import org .springframework .core .env .Environment ;
48import org .springframework .stereotype .Service ;
59
610@ Service
7- public class FooService implements IFooService {
11+ public class FooService implements IFooService , InitializingBean {
12+
13+ @ Value ("${foo1}" )
14+ private String foo1 ;
15+
16+ @ Autowired
17+ private Environment env ;
818
919 public FooService () {
1020 super ();
@@ -17,4 +27,10 @@ public Foo findOne(final Long id) {
1727 return new Foo ();
1828 }
1929
30+ @ Override
31+ public final void afterPropertiesSet () {
32+ System .out .println ("In Parent Context, property via @Value = " + foo1 );
33+ System .out .println ("In Parent Context, property via env = " + env .getProperty ("foo2" ));
34+ }
35+
2036}
Original file line number Diff line number Diff line change 22
33import org .baeldung .service .IFooService ;
44import org .baeldung .web .dto .Foo ;
5+ import org .springframework .beans .factory .InitializingBean ;
56import org .springframework .beans .factory .annotation .Autowired ;
7+ import org .springframework .beans .factory .annotation .Value ;
8+ import org .springframework .core .env .Environment ;
69import org .springframework .stereotype .Controller ;
710import org .springframework .web .bind .annotation .PathVariable ;
811import org .springframework .web .bind .annotation .RequestMapping ;
912import org .springframework .web .bind .annotation .RequestMethod ;
1013import org .springframework .web .bind .annotation .ResponseBody ;
1114
1215@ Controller
13- @ RequestMapping (value = "/foo" )
14- public class FooController {
16+ @ RequestMapping (value = "/foos" )
17+ public class FooController implements InitializingBean {
18+
19+ @ Value ("${foo1}" )
20+ private String foo1 ;
21+
22+ @ Autowired
23+ private Environment env ;
1524
1625 @ Autowired
1726 private IFooService service ;
@@ -28,4 +37,10 @@ public Foo findOne(@PathVariable("id") final Long id) {
2837 return service .findOne (id );
2938 }
3039
40+ @ Override
41+ public final void afterPropertiesSet () {
42+ System .out .println ("In Child Context, property via @Value = " + foo1 );
43+ System .out .println ("In Child Context, property via env = " + env .getProperty ("foo2" ));
44+ }
45+
3146}
Original file line number Diff line number Diff line change 1+ foo1 =bar1
2+ foo2 =bar2
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <beans xmlns =" http://www.springframework.org/schema/beans"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xmlns : context =" http://www.springframework.org/schema/context"
5+ xsi : schemaLocation ="
6+ http://www.springframework.org/schema/beans
7+ http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
8+ http://www.springframework.org/schema/context
9+ http://www.springframework.org/schema/context/spring-context-4.0.xsd" >
10+
11+ <context : property-placeholder location =" classpath:foo.properties" />
12+
13+ </beans >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3737 <url-pattern >/api/*</url-pattern >
3838 </servlet-mapping >
3939
40-
4140 <!-- Spring Security -->
4241 <filter >
4342 <filter-name >springSecurityFilterChain</filter-name >
You can’t perform that action at this time.
0 commit comments