본문 바로가기

Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Total
Today
Yesterday
관리 메뉴

8-3 본문

집에서 공부

8-3

잠이올때마다 2019. 3. 7. 23:09

package com.javalec.ex;


import java.util.Scanner;


import org.springframework.context.support.GenericXmlApplicationContext;


public class MainClass {


public static void main(String[] args) {


String config = null;

Scanner scanner = new Scanner(System.in);

String str = scanner.next();

if(str.equals("dev")){

config = "dev";

}

else if(str.equals("run")){

config="run";

}

scanner.close();

GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();

ctx.getEnvironment().setActiveProfiles(config);

ctx.load("applicationCTX_dev.xml","applicationCTX_run.xml");

ServerInfo info = ctx.getBean("ServerInfo", ServerInfo.class);

System.out.println("ip: " + info.getIp());

System.out.println("port: " + info.getPort());

ctx.close();

}

}


applicationCTX_run.xml


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"

profile="run"> <-핵심  귀찮아서 코드만 넣어야겠다.

    <bean id="ServerInfo" class="com.javalec.ex.ServerInfo">

    <property name="ip" value="44.233"></property>

    <property name="port" value="8000045"></property>

</bean>


</beans>




'집에서 공부' 카테고리의 다른 글

10-1 AOP2  (0) 2019.03.12
9-3  (0) 2019.03.07
8-2  (0) 2019.03.07
8-1  (0) 2019.03.06
7-3  (0) 2019.03.06
Comments