我正在尝试使用AOP技术学习Spring框架。为此,我创建了一个普通的Java项目(没有Maven)并导入了弹簧罐spring
以及AOP AspectJ
的罐子(请参阅下面的屏幕截图)。
之前一切正常,我得到了输出Circle name
。
但是第二天我又尝试再次运行该项目,但是我收到窗口错误The selection did not contain any resource that can run on a server
。因此,如果我右键单击AopMain
类,则在出现错误后,我无法在服务器上运行该类。要再次获得该选项,我必须重新启动eclipse并启动Tomcat 7服务器。
我该怎么做才能解决错误?
AopMain
package org.stack;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.stack.service.ShapeService;
public class AopMain {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"file:src/spring.xml");
ShapeService shapeService = (ShapeService) ctx
.getBean("shapeService", ShapeService.class);
System.out.println(shapeService.getCircle().getName());
}
}
环
package org.stack.model;
public class Circle {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
三角
package org.stack.model;
public class Triangle {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
ShapeService
package org.stack.service;
import org.stack.model.Circle;
import org.stack.model.Triangle;
public class ShapeService {
private Circle circle;
private Triangle triangle;
public Circle getCircle() {
return circle;
}
public void setCircle(Circle circle) {
this.circle = circle;
}
public Triangle getTriangle() {
return triangle;
}
public void setTriangle(Triangle triangle) {
this.triangle = triangle;
}
}
Spring.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" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<aop:aspectj-autoproxy />
<bean name="triangle" class="org.stack.model.Triangle">
<property name="name" value="Triangle name"></property>
</bean>
<bean name="circle" class="org.stack.model.Circle">
<property name="name" value="Circle name"></property>
</bean>
<bean name="shapeService" class="org.stack.service.ShapeService"
autowire="byName">
</bean>
<!-- <bean name="loggingAspect" class="org.stack.aspect.LoggindAdvice"></bean> -->
</beans>
错误