0

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");
4
  • 2.5.6.SEC03 what? Why are you using XML config with Spring 4? My eyes... Commented Jul 23, 2015 at 9:27
  • what do I have to use? Commented Jul 23, 2015 at 9:34
  • Annotation based config using Java. XML is so 2000 Commented May 29, 2016 at 4:19
  • Take a look here Commented May 29, 2016 at 4:24

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.