package com.nw.promotion.test;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
public class MainTest implements IMainTest {
private static final Logger logger = Logger.getLogger(MainTest.class);
private static ApplicationContext context;
public MainTest() {
logger.info("我是构造器!");
}
@PostConstruct
public void postConstructTest() {
logger.info(" Test PostConstruct Annotation!");
}
@PreDestroy
public void preDestroyTest() {
logger.info(" Test PreDestroy Annotation!");
}
public static void main(String[] args) throws RuntimeException, Exception {
IMainTest test = (MainTest) context.getBean("mainTest");
logger.info("我是异步执行的前!!!");
test.asyncTest();
logger.info("我是异步执行的后!!!");
}
@Override
public void aopTest(String parameter) {
System.out.println("Hello World :" + parameter);
}
@Async
@Override
public void asyncTest() {
logger.info("我是异步执行的!!!");
}
static {
context = new ClassPathXmlApplicationContext("spring/ApplicationContext.xml",
"spring/ApplicationContext-DB.xml");
}
}
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
public class MainTest implements IMainTest {
private static final Logger logger = Logger.getLogger(MainTest.class);
private static ApplicationContext context;
public MainTest() {
logger.info("我是构造器!");
}
@PostConstruct
public void postConstructTest() {
logger.info(" Test PostConstruct Annotation!");
}
@PreDestroy
public void preDestroyTest() {
logger.info(" Test PreDestroy Annotation!");
}
public static void main(String[] args) throws RuntimeException, Exception {
IMainTest test = (MainTest) context.getBean("mainTest");
logger.info("我是异步执行的前!!!");
test.asyncTest();
logger.info("我是异步执行的后!!!");
}
@Override
public void aopTest(String parameter) {
System.out.println("Hello World :" + parameter);
}
@Async
@Override
public void asyncTest() {
logger.info("我是异步执行的!!!");
}
static {
context = new ClassPathXmlApplicationContext("spring/ApplicationContext.xml",
"spring/ApplicationContext-DB.xml");
}
}