我正在获取以下代码的堆栈跟踪,
public interface SequenceDAO {
public Sequence getSequence(String sequenceId);
public int getNextValue(String sequenceId);
}
``````````````````````````````````````````
public class Sequence {
private int initial;
private String prefix;
private String suffix;
public Sequence(int initial, String prefix, String suffix) {
this.initial = initial;
this.prefix = prefix;
this.suffix = suffix;
}
``````````````````````````````````````````````` `
@Component("SequenceDAO")
public class SequenceDAOImpl implements SequenceDAO {
private Map<String, Sequence> sequences;
private Map<String, Integer> values;
public SequenceDAOImpl() {
sequences = new HashMap<>();
sequences.put("IT", new Sequence(30, "IT", "A"));
values = new HashMap<>();
values.put("IT", 10000);
}
@Override
public Sequence getSequence(String sequenceId) {
return sequences.get(sequenceId);
}
@Override
public int getNextValue(String sequenceId) {
int value = values.get(sequenceId);
values.put(sequenceId, value + 1);
return value;
}
}
``````````````````````````````````````````````< / p>
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.scan("com.example");
SequenceDAO obj = context.getBean("SequenceDAO", SequenceDAO.class);
System.out.println(obj.getNextValue("IT"));
System.out.println(obj.getSequence("IT"));
}
``````````````````````````````````````````````` ``````````
Exception in thread "main" java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@4c0bc4 has not been refreshed yet
at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1041)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1059)
at com.example.SpringAnnotationsSequenceGeneratorWithDaoIntroductionApplication.main(SpringAnnotationsSequenceGeneratorWithDaoIntroductionApplication.java:14)
我刚接触春天,我正在学习没有注释的春天,所以如果有人能告诉我这里发生了什么错误
任何帮助都是明确的。
Beat Regards
答案 0 :(得分:0)
您的上下文init
应该是这样的:
ApplicationContext aContext = new AnnotationConfigApplicationContext(ConcertConfig.class);
@Configuration
@EnableAspectJAutoProxy
@ComponentScan
public class ConcertConfig {
}