我正面臨模板設計模式的春天配置問題。模板設計模式彈簧配置問題
App.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "Spring-Module.xml" })
public class App {
@Autowired
@Qualifier("userExecutor")
private IExecutor userExecutor;
public void print(){
System.out.println(userExecutor.execute());
}
}
彈簧Module.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans default-lazy-init="true"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:annotation-config />
<context:component-scan base-package="com.ravi" />
</beans>
IExecutor.java
public interface IExecutor {
public Object execute();
}
AbstractExecutor.java
public abstract class AbstractExecutor implements IExecutor {
private IInputPropertyBean inputObject;
private IOutputPropertyBean outputObject;
public abstract IAttribute getInputValues(Object inputObject);
public abstract IAttribute process(IAttribute inputPropertyBean);
public abstract IOutputPropertyBean getOutputValues(IAttribute outputPropertyBean, IOutputPropertyBean outObject);
public AbstractExecutor(IInputPropertyBean inputObject, IOutputPropertyBean outputObject) {
this.inputObject = inputObject;
this.outputObject = outputObject;
}
@Override
public Object execute() {
IAttribute inputAttribute = getInputValues(inputObject);
IAttribute outputAttribute = process(inputAttribute);
outputObject = (IOutputPropertyBean) getOutputValues(outputAttribute, outputObject);
return outputObject;
}
}
AbstractUserExecutor.java
public abstract class AbstractUserExecutor extends AbstractExecutor {
public AbstractUserExecutor(IInputPropertyBean inputObject, IOutputPropertyBean outputObject) {
super(inputObject, outputObject);
}
@Override
public IAttribute getInputValues(Object inputObject) {
System.out.println("getInputValues");
return null;
}
@Override
public IOutputPropertyBean getOutputValues(IAttribute outputPropertyBean, IOutputPropertyBean outObject) {
System.out.println("getOutputValues");
return null;
}
}
UserExecutor.java
@Repository("userExecutor")
public class UserExecutor extends AbstractUserExecutor {
@Autowired
@Qualifier("userInput")
private IInputPropertyBean inputObject;
@Autowired
@Qualifier("userOutput")
private IOutputPropertyBean outputObject;
public UserExecutor(IInputPropertyBean inputObject, IOutputPropertyBean outputObject) {
super(inputObject, outputObject);
}
@Override
public IAttribute process(IAttribute inputPropertyBean) {
System.out.println("process");
return null;
}
}
IInputPropertyBean.java
public interface IInputPropertyBean {}
IOutputPropertyBean.java
public interface IOutputPropertyBean { }
UserInput.java
@Component("userInput")
public class UserInput implements IInputPropertyBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
UserOutput.java
@Component("userOutput")
public class UserOutput implements IOutputPropertyBean {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
IAttribute.java
public interface IAttribute { }
用戶的.java
@Component
public class User implements IAttribute{
}
這是什麼問題?錯誤異常? – SMA