java - Connecting to database using Spring JDBC -
i trying connect database using spring jdbc
beans.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="org.postgresql.driver" /> <property name="url" value="jdbc:postgresql://localhost:5434/lab1_aop" /> <property name="username" value="postgres" /> <property name="password" value="passw" /> </bean> </beans>
the place want make connection:
public class bookservice { private connection connection; public bookservice() { applicationcontext context = new classpathxmlapplicationcontext("beans.xml"); } }
i these errors
the constructor classpathxmlapplicationcontext(string) refers missing type beansexception bookservice.java type org.springframework.beans.beansexception cannot resolved. indirectly referenced required .class files
what doing wrong?
you need add spring-context
, spring-beans
dependency it, if using maven.
for better dependency management use maven or gradle
.
add in pom.xml
:
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>{spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>{spring.version}</version> </dependency>
Comments
Post a Comment