@Configuration
@EnableWebMvc
@EnableScheduling
@Import({DataBaseConfig.class})
@ComponentScan({"com.cyonesoft","com.emunhi.comm"})
@MapperScan("com.cyonesoft.web")
@PropertySource("classpath:config/${spring.profiles.active:office}/properties/application.properties")
public class WebConfig implements WebMvcConfigurer {
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigPlaceon() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
public PropertiesFactoryBean applicationProperties() {
PropertiesFactoryBean bean = new PropertiesFactoryBean();
bean.setFileEncoding("UTF-8");
bean.setLocation(new ClassPathResource("config/"+System.getProperty("spring.profiles.active","office")+"/properties/application.properties"));
return bean;
}
@Controller
public class LoginController {
static final Logger logger = LoggerFactory.getLogger(LoginController.class);
@Value("${database.url}")
private String databaseUrl;
@RequestMapping(value="/login")
public String login( Model model, HttpServletRequest req) throws Exception {
System.out.println(databaseUrl);
return "login/login";
}
@Controller
public class LoginController {
static final Logger logger = LoggerFactory.getLogger(LoginController.class);
@Value("#{applicationProperties['database.url']}")
private String databaseUrl;
@RequestMapping(value="/login")
public String login( Model model, HttpServletRequest req) throws Exception {
System.out.println(databaseUrl);
return "login/login";
}
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
[ in javascript ]
<spring:eval expression="@applicationProperties['database.url']" var="dbUrl"/>
var db = "${dbUrl}";
[ in jsp ]
<spring:eval expression="@applicationProperties['database.url']"/>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<script type="text/javascript">
$(function(){
$.callbackLink = function(result){
if(result.result=="OK"){
<spring:eval expression="@applicationProperties['agent.url']" var="agentUrl"/>
result.url = "${agentUrl}/login/agent";
} else {
alert(result.msg);
}
};
});
</script>
</head>
<body>
<div style="margin:10px;">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:com/config/${spring.profiles.active}/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dtSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
/**
* @author emunhi
*
*/
@Configuration
@PropertySource("classpath:com/config/${spring.profiles.active}/application.properties")
public class AppConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}
@Controller
@RequestMapping("/service")
public class PublicServiceController {
@Value("${service.allow.ip}")
String allowedIp;
@Resource(name = "userService")
private UserService userService;
# 폴더정보
PATH.ROOT=/data/image
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
/**
* @author emunhi
*
*/
@Configuration
@PropertySource("classpath:resources/config/env.properties")
public class WebConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfig() {
return new PropertySourcesPlaceholderConfigurer();
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Repository;
/**
* @author emunhi
*
*/
@Repository
public class UtProperty {
static Environment environment;
@Autowired
public void setEnvironment(Environment env) {
environment = env;
}
public static String getProperty(String key) {
return environment.getProperty(key);
}
}
// java 파일 아무데서나 취득가능
public String getRootPath() {
String pathRoot = UtProperty.getProperty("PATH.ROOT");
return pathRoot;
}