构建Spring开发环境的小示例

一、添加Spring的jar支持包

二、添加Spring的核心文件 applicationContext.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">

<bean id="HelloWorld" class="com.demo.spring.HelloWorld">
<property name="message"><value>world</value></property>
</bean>
</beans>

三、添加日志配置文件:log4j.properties

## LOGGERS ##
#define a logger 
#log4j.rootLogger=DEBUG,console,file
log4j.rootLogger=INFO,console,file

## APPENDERS ##
# define an appender named console, which is set to be a ConsoleAppender
log4j.appender.console=org.apache.log4j.ConsoleAppender

# define an appender named file, which is set to be a RollingFileAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=d:/demo_log.txt

#set the log's size
log4j.appender.file.MaxFileSize=1000KB
log4j.appender.file.MaxBackupIndex=20

## LAYOUTS ##
# assign a SimpleLayout to console appender
log4j.appender.console.layout=org.apache.log4j.SimpleLayout

# assign a PatternLayout to file appender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
# For debug
# log4j.appender.file.layout.ConversionPattern=[%-5p][%t][%C][%d{yyyy-MM-dd HH:mm:ss}] %m%n
# For deployment
log4j.appender.file.layout.ConversionPattern=[%-5p][%d{yyyy-MM-dd HH:mm:ss}] %m%n 

 项目的目录

com.demo.spring.HelloWorld的代码:

package com.demo.spring;

public class HelloWorld {
protected String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
public String excute(){
return "Hello"+getMessage();
}
}

com.demo.test.Test的代码:

package com.demo.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.demo.spring.HelloWorld;

public class Test {
public static void main(String args[]){
ApplicationContext ctx=new FileSystemXmlApplicationContext(
"WebContent/WEB-INF/applicationContext.xml");
HelloWorld hello=(HelloWorld) ctx.getBean("HelloWorld");
System.out.println(hello.excute());
}
}

输出结果如下:

INFO - Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@4b222f: startup date [Tue Jul 12 00:01:34 CST 2011]; root of context hierarchy
INFO - Loading XML bean definitions from file [D:\My Documents\eclipse workspace\test\WebContent\WEB-INF\applicationContext.xml]
INFO - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1c9b9ca: defining beans [HelloWorld]; root of factory hierarchy
Helloworld 
 

出现Helloworld字样说明Spring的支持环境已经构建完毕。

附:源码下载http://u.115.com/file/bh56mqty

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux中,可以通过sysconf(_SC_CLK_TCK)函数来获取系统的tick计数频率。这个频率表示内核的计时频率,而不是运行频率。具体的代码示例如下: #include <stdio.h> #include <unistd.h> #include <sys/times.h> int main() { long sysHz = sysconf(_SC_CLK_TCK); printf("系统的tick计数频率为:%ld\n", sysHz); unsigned long tickCount = (unsigned long) times(NULL); printf("当前tick计数为:%ul\n", tickCount); sleep(1); tickCount = (unsigned long) times(NULL); printf("一后的tick计数为:%ul\n", tickCount); sleep(1); tickCount = (unsigned long) times(NULL); printf("再过一后的tick计数为:%ul\n", tickCount); return 0; } 这段代码会输出系统的tick计数频率以及当前的tick计数,然后分别让程序休眠1并再次获取tick计数。这样就可以通过比较tick计数的差值来得到时间的流逝。注意,tick计数的单位是时钟滴答数,需要根据tick计数频率转换为实际的时间单位。 另外,在Linux中还可以使用clock_gettime函数来获取系统的时间。CLOCK_MONOTONIC代表系统启动后流逝的时间,而CLOCK_REALTIME代表现实的时间。具体的代码示例如下: #include <stdio.h> #include <time.h> int main() { struct timespec tp; clock_gettime(CLOCK_MONOTONIC, &tp); printf("系统启动后流逝的时间为:%ld %ld纳\n", tp.tv_sec, tp.tv_nsec); clock_gettime(CLOCK_REALTIME, &tp); printf("现实的时间为:%ld %ld纳\n", tp.tv_sec, tp.tv_nsec); return 0; } 这段代码会输出系统启动后流逝的时间和现实的时间,单位分别是和纳
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值