编程语言
首页 > 编程语言> > Spring的基于Java的配置不适用于我

Spring的基于Java的配置不适用于我

作者:互联网

我是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的配置…

提前致谢,

解决方法:

从异常的角度来看:

java.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.

标签:netbeans,glassfish,spring,java-ee
来源: https://codeday.me/bug/20191202/2086169.html