WorldCats
WorldCats
2017-09-15 08:43

新手求eclipse上Spring运行时的;在运用@Test注解运行后没有问题过一段时间就会无法运行

5
  • spring
  • 图片
  • eclipse

public class Car {

private String name;
private int price;
@Override
public String toString() {
    return "Car [name=" + name + ", price=" + price + "]";
}
public Car(String name, int price) {
    super();
    this.name = name;
    this.price = price;
}

}

public class Preson {

private String name;
private Car car;
@Override
public String toString() {
    return "Preson [name=" + name + ", car=" + car + "]";
}
public Preson(String name, Car car) {
    super();
    this.name = name;
    this.car = car;
}

}
---------------以下为application.properties的配置文件
<?xml version="1.0" encoding="UTF-8"?>
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="car1" class="com.Car">
    <!-- <constructor-arg name="name" value="上海大众"></constructor-arg>
    <constructor-arg name="price" value="90000"></constructor-arg> -->
    <constructor-arg index="0" value="小汽车" />
    <constructor-arg index="1" value="10000" />
</bean>

<bean id="preson" name="com.Preson">
    <constructor-arg name="name" value="小李" />
    <constructor-arg name="car" ref="car1"/>
</bean>


----------------log4j.properties的配置文件

Global logging configuration

log4j.rootLogger=WARN, stdout

Console output...

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答