精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-10-04
最后修改:2008-12-13
众所周知spring框架是一个非常优秀的轻量级框架工具,我们借助它可以简单的将软件各个部分割裂开以实现较低的耦合度。 #System environment
Ubuntu 7.10 Linux Eclipse Platform Version: 3.3.0 + MyEclipse 6.0
其中spring框架的加载和配置是通过MyEclipse的插件(MyEclipse-->Project Capabilities-->Add Spring ...-->Spring 2.0 Core ...)实现的。
<?
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-2.0.xsd" > < bean id ="HelloWorld" class ="springapp.hello.HelloWorld" > < property name ="message" > < value > world </ value > </ property > </ bean > </ beans >
package
springapp.hello;
public interface Hello { public String sayHello(); }
package
springapp.hello;
public class HelloWorld implements Hello { private String message; public HelloWorld() { message = null ; } public String sayHello() { return " Hello " + message + " ! " ; } public String getMessage() { return message; } public void setMessage(String message) { this .message = message; } }
package
springapp.main;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; import springapp.hello.Hello; public class Main { /** * @param args */ public static void main(String[] args) { ApplicationContext ctx = new FileSystemXmlApplicationContext( " /src/applicationContext.xml " ); Hello h = (Hello)ctx.getBean( " HelloWorld " ); System.out.println(h.sayHello()); } }
2008
-
02
-
14
14
:
50
:
55
,
954
INFO
[ org.springframework.context.support.FileSystemXmlApplicationContext ] - Refreshing org.springframework.context.support.FileSystemXmlApplicationContext @f3d6a5: display name [ org.springframework.context.support.FileSystemXmlApplicationContext@f3d6a5 ] ; startup date [Thu Feb 14 14:50:55 CST 2008]; root of context hierarchy 2008 - 02 - 14 14 : 50 : 56 , 013 INFO [ org.springframework.beans.factory.xml.XmlBeanDefinitionReader ] - Loading XML bean definitions from file [ /home/wpc/workspace/Java/MyStudy/SimplifySpringCoreJar/src/applicationContext.xml ] 2008 - 02 - 14 14 : 50 : 56 , 197 INFO [ org.springframework.context.support.FileSystemXmlApplicationContext ] - Bean factory for application context [ org.springframework.context.support.FileSystemXmlApplicationContext@f3d6a5 ] : org.springframework.beans.factory.support.DefaultListableBeanFactory@f7f540 2008 - 02 - 14 14 : 50 : 56 , 210 INFO [ org.springframework.beans.factory.support.DefaultListableBeanFactory ] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f7f540 : defining beans [ HelloWorld ] ; root of factory hierarchy Hello world!
由于有个log配置文件的问题可能有些程式运行会有警告信息,这个不要紧,不再讨论范畴。
#
For
JBoss: Avoid to setup Log4J outside
$
JBOSS_HOME
/
server
/
default
/
deploy
/
log4j
.
xml!
# For all other servers: Comment out the Log4J listener in web . xml to activate Log4J . log4j . rootLogger = INFO , stdout , logfile log4j . appender . stdout = org . apache . log4j . ConsoleAppender log4j . appender . stdout . layout = org . apache . log4j . PatternLayout log4j . appender . stdout . layout . ConversionPattern = %d %p [%c] - %m%n log4j . appender . logfile = org . apache . log4j . RollingFileAppender # The log file's location log4j . appender . logfile . File = springframe_log . log log4j . appender . logfile . MaxFileSize = 512KB # Keep three backup files . log4j . appender . logfile . MaxBackupIndex = 3 # Pattern to output: data priority [category] -message log4j . appender . logfile . layout = org . apache . log4j . PatternLayout log4j . appender . logfile . layout . ConversionPattern = %d %p [%c] - %m%n
文件命名为log4j.properties然后打包jar并且导入即可。 */可能可以再次简化,但是我没有继续进行,如果有兴趣可以继 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 2589 次