我是Spring编程的新手,目前正在为Spring 3.1的Java Based Configuraion挣扎.
@Configuration
@ImportResource("classpath:/resources/jdbc.properties")
public class AppConfig {
@Autowired
Environment env;
private @Value("${jdbc.url}")
String url;
private @Value("${jdbc.username}")
String username;
private @Value("${jdbc.password}")
String password;
@Bean
public DataSource dataSource() {
System.out.println("Creating data Source.");
return new DriverManagerDataSource(url,username,password);
}
@Bean
public SessionFactory sessionFactory () throws Exception {
return new AnnotationSessionFactoryBuilder().setDataSource(dataSource()).setPackagesToScan("com.argusoft.loginmodule.domain").buildSessionFactory();
}
}
现在,当我尝试运行项目时,出现以下错误.
输出值
SEVERE: Exception while loading the app :
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
java.lang.IllegalArgumentException: javax.servlet.ServletException:
java.lang.NoClassDefFoundError:
org/springframework/core/env/EnvironmentCapable
陷入其中,无法解决它…..我在关注Spring Source Blog.
还请提出一些好的教程,其中通过易于理解的示例来说明Spring最新的基于Java的配置…
提前致谢,
最佳答案
从异常的角度来看:
原文链接:https://www.f2er.com/spring/531750.htmljava.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable
该问题等于问题:Spring class EnvironmentCapable
因此正确的答案可能是:
I think that need use version 3.1.0 – in package
org.springframework.core-3.1.0.M2.jar this class presents.
由user810430在此处给出:original answer.