使用intelliJ建立一个sql连接来运行一个spring-mvc项目

时间:2014-05-14 15:08:42

标签: spring-mvc intellij-idea

我已经将一个spring-mvc项目克隆到我的计算机上,并尝试使用intelliJ来运行它。根据{{​​3}},我似乎需要建立一个SQL连接。我是否需要将mysql下载到我的计算机,创建一个帐户并在我的connection.XML文件中输入该信息(如下所示)?

<?xml version="1.0" encoding="UTF-8"?>
<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">

<!--  Data Source Setup -->
<bean id="hsqldataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <property name="url" value="jdbc:hsqldb:hsql" />
    <property name="username" value="example" />
    <property name="password" value="example" />
</bean>
<bean id="mysqldataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://192.168.0.0.0:3306/dev" />
<property name="username" value="example" />
    <property name="password" value="example" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
        <list>
            <value>example/peer-review/domain/hibernatemapping/Division.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/Modality.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/Score.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/User.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/QaCase.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/Review.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/Exam.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/Patient.hbm.xml</value>
            <value>example/peer-review/domain/hibernatemapping/Role.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
        </props>
    </property>
    <property name="dataSource" ref="hsqldataSource" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<!--  Dao Layer generic config-->    
<bean id="abstractDaoTarget" class="example.peer-review.persistence.hibernate.GenericDAOHibernateImpl" abstract="true">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!--  Dao Layer instances -->
<bean id="DivisionDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.DivisionDAOHibernateImpl" />
<bean id="ModalityDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ModalityDAOHibernateImpl" />
<bean id="ScoreDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ScoreDAOHibernateImpl" />
<bean id="UserDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.UserDAOHibernateImpl" />
<bean id="ReviewDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ReviewDAOHibernateImpl" />
<bean id="QaCaseDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.QaCaseDAOHibernateImpl" />
<bean id="ExamDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ExamDAOHibernateImpl" />
<bean id="PatientDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.PatientDAOHibernateImpl" />
<bean id="RoleDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.RoleDAOHibernateImpl" />

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
  <property name="url" value="ldap://example.edu:1234" />
  <property name="base" value="" />
  <property name="userDn" value="cn=Test1" />
  <property name="password" value="Test1" />
  <property name="authenticationStrategy" ref="ldapAuthStrat" />
</bean>

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <constructor-arg ref="contextSource" />
</bean>

<bean id="ldapAuthStrat" class="org.springframework.ldap.core.support.ExternalTlsDirContextAuthenticationStrategy" />
</beans>

1 个答案:

答案 0 :(得分:1)

您的conf文件包含两个不同数据源的定义,hsql和mysql。 hsql是一个内存db。

Mysql是独立的数据库应用程序。

是连接到mysql源,需要下载mysql并设置users / schema。