简体   繁体   中英

Spring Application Context configuration: class not found exception

When I start my web application, I get from init():

    java.lang.ClassNotFoundException:org.springframework.context.ApplicationContext

maybe I miss something I my configuration files.

In pom.xml I have this 2 spring dependencies:

[...]
    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring</artifactId>
  <version>2.5.6.SEC03</version>
</dependency>
    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>4.1.6.RELEASE</version>
</dependency>
<dependency>
[...]

and in Datasource.xml I have beans and listener declared:

<bean id="dataSource" destroy-method="close"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/Rubrica" />
<property name="username" value="user" />
<property name="password" value="pass" />
  </bean>

  <bean id="JDBC_Spring_EntryDAO" class="net.tirasa.jdbc_spring_addressbook.JDBC_Spring_EntryDAO">  
<property name="JDBC_Spring_EntryDAO" ref="JDBC_Spring_EntryDAO" />
<property name="dataSource" ref="dataSource" />
  </bean>

</beans>

<listener>
  <listenerclass>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

The log message switched misteriously to

class path resource [Spring-Datasource.xml] cannot be opened because it does not exist

That is good to me, since it looks like I have to put the Spring-Datasource.xml file into the right path, or I have to specify the right path in the command line

    ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Datasource.xml");
    dataSource = (DataSource) context.getBean("JDBC_Spring_EntryDAO");

Use Spring 4 core and context:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.0.0.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>4.0.0.RELEASE</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM