PropertiesResolver

This commit is contained in:
lukasgol committed 2014-04-05 16:16:35 +02:00
1 parent 14eb735ff8
commit c6f7e13b5d
5 files changed
+66 -2

No files matched your search

+3 -2
View File
@@ -2,8 +2,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
/**
* Created by lukasgol on 01.04.14.
*/
@@ -11,7 +9,10 @@ import org.springframework.context.annotation.ImportResource;
@EnableAutoConfiguration
@ImportResource("Spring-Module.xml")
public class Config {
public static void main(String[] args){
SpringApplication.run(Config.class, args);
}
}
+23
View File
@@ -2,14 +2,25 @@
* Created by lukasgol on 01.04.14.
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import utils.PropertiesSolver;
@Controller
@PropertySource("app.properties")
public class Controller_test {
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
PropertiesSolver ps;
@Value("${my.prop}")
String val;
@RequestMapping("/action")
public
@ResponseBody
@@ -24,5 +35,17 @@ public class Controller_test {
String hello(@RequestParam(value = "action", required = false, defaultValue = "empty") String action) {
return "Just String: "+action;
}
@RequestMapping("/val")
@ResponseBody
String getVal(@RequestParam(value = "param", required = false, defaultValue = "my.prop") String param){
String recived_val;
if (param.equals("my.prop"))return "property "+param+" is: "+ val ;
else if((recived_val=ps.getProperty(param))!=null){
return "property "+param+" is: "+ recived_val;
}
else return "not found";
}
}
+30
View File
@@ -0,0 +1,30 @@
package utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
* Created by lukasgol on 05.04.14.
*/
@Component
@PropertySource("app.properties")
public class PropertiesSolver {
@Autowired
Environment env;
@Value("${my.prop}")
String val;
public PropertiesSolver() {
}
public String getProperty(String param){
System.out.println(val);
return env.getProperty(param);
}
}
+8
View File
@@ -14,5 +14,13 @@
<property name="port" value="1099"/>
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>app.properties</value>
</property>
</bean>
</beans>
+2
View File
@@ -0,0 +1,2 @@
my.prop=avalue
lala=lala