1

私の pom.xml は次のとおりです。

<modelVersion>4.0.0</modelVersion>
<groupId>org.aio</groupId>
<artifactId>aio-core</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>aio</name>

<properties>
    <org.springframework.version>3.1.1.RELEASE</org.springframework.version>
    <org.springframework.security.version>3.0.2.RELEASE</org.springframework.security.version>
    <aspectj.version>1.6.9.M2</aspectj.version>
    <org.slf4j.version>1.6.1</org.slf4j.version>
    <hibernate.version>4.1.4.FINAL</hibernate.version>
    <hibernate.jpa.version>1.0.1.Final</hibernate.jpa.version>
    <commons-dbcp.version>1.4</commons-dbcp.version>
    <jackson.mapper.version>1.8.2</jackson.mapper.version>
    <freemarker.version>2.3.18</freemarker.version> 
</properties>
<build>
    <plugins>
        <!-- Configuration which allows JUnit tests to be placed in the same folder 
            as java files -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <testClassesDirectory>${project.build.directory}/test-classes/</testClassesDirectory>
            </configuration>
        </plugin>
    </plugins>
    <!-- <filters> -->
    <!-- filter files DONT end up in WAR file. -->
    <!-- <filter>src/main/recources/jdbc.properties</filter> -->
    <!-- </filters> -->
    <!-- Configuration which allows configuration files (such as xml files) 
        to be placed in the same folder as java files -->
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources/</directory>
        </resource>
    </resources>
</build>


<dependencies>
    <!-- ********************************************************************** 
        ** SPRING DEPENDENCIES ** ********************************************************************** -->
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${org.springframework.version}</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework.version}</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>


    <!-- Security -->
    <!--  
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
    -->


    <!-- URL Rewrite -->
    <dependency>
        <groupId>org.tuckey</groupId>
        <artifactId>urlrewritefilter</artifactId>
        <version>3.1.0</version>
        <scope>runtime</scope>
    </dependency>

    <!-- HIBERNATE DEPENDENCIES -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.spec.javax.transaction</groupId>
                <artifactId>jboss-transaction-api_1.1_spec</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>${hibernate.jpa.version}</version>
    </dependency> 
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>


    <!-- ********************************************************************** 
        ** OTHER DEPENDENCIES ** ********************************************************************** -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jcl</artifactId>
        <version>${org.slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${aspectj.version}</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>



    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <type>jar</type>
        <scope>provided</scope>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <type>jar</type>
        <scope>provided</scope>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <type>jar</type>
        <scope>provided</scope>
        <optional>false</optional>
    </dependency>

    <!-- File upload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>${commons-dbcp.version}</version>
    </dependency>

    <!-- ********************************************************************** 
        ** TEST DEPENDENCIES ** ********************************************************************** -->

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>1.8.0.10</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.4.0</version>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.17</version>
        <optional>false</optional>
    </dependency>
    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.mapper.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>${jackson.mapper.version}</version>
    </dependency>
    <!-- Jackson JSON Mapper end -->

    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>${freemarker.version}</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>



<repositories>
    <repository>
        <id>repository.springframework.milestone</id>
        <name>Spring Framework Maven Milestone Repository</name>
        <url>http://maven.springframework.org/milestone</url>
    </repository>
    <repository>
        <id>spring-releases</id>
        <name>Spring Maven RELEASE Repository</name>
        <url>http://maven.springframework.org/release</url>
    </repository>
    <repository>
        <id>repository.jboss.org-public</id>
        <name>JBoss.org Maven repository</name>
        <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
    <repository>
        <id>EclipseLink Repo</id>
        <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
    </repository>
</repositories>

および春の構成ファイル app-context.xml:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>
        </list>
    </property>
</bean>

<context:annotation-config/>


<aop:aspectj-autoproxy />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="defaultAutoCommit" value="false" />
</bean>

 <!-- JPA EntityManagerFactoryBean for EntityManager-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceXmlLocation" value="classpath:persistence.xml" />
    <property name="persistenceUnitName" value="persistenceUnit" />
    <property name="jpaPropertyMap">
        <props>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        </props>
    </property>
</bean>


<!-- Transaction manager for JPA -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory">
        <ref bean="entityManagerFactory" />
    </property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<context:component-scan base-package="org.aio.*">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

アプリがWebサーバーで実行されている場合は問題ありませんが、junitテストを実行している場合は次のようになります:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Article is not mapped [select count(*) from Article]

しかし、Article.class をコピーしてクラスパス 'target/test-classes/org/aio/modules/' をテストすると、再び機能するようになるので、クラスパス内の注釈付きエンティティを休止状態で自動スキャンする方法に興味がありました。助けてください。

ソースコード: https://code.google.com/p/jpa2-spring3-aio/source/checkout

4

1 に答える 1