xml file problems and solutions in the engineering code does not compile the src directory of java

Maven project IDEA, the default source directory ( src/main/javathe directory) of xml files and other resources will not be packaged into a folder classes at compile time, but directly discard. If you are using Eclipse, xml and other Eclipse-src directory under the resource files automatically at compile time to classes packed into output folder.

Example:

When used in MyBatis IDEA, it would typically create a SQL mapping configuration file, if the file is in src / main / java directory, compiled in the target directory is not found in this document

image description

For this issue of IDEA, the following solution:

The first method: If no special business, no need to specify resource files navigate to the src / main / java, you can create a main / resources directory under src, and place in which to require xml resource files. Tools maven default at compile time, the resource file folder resources will be packaged into a piece of classes directory.

image description

For this use of MyBatis, we must specify the location mapper.xml file in the configuration file, for example, an increase in application.properties in springboot project:

mybatis.mapper-locations=classpath:mapper/*.xml

If an ordinary ssm project, then this configuration:

<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="druidDataSource"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> <!-- 配置mapper文件的位置 --> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean>

The second method: the configuration file to configure the maven pom, find the <build> pom node file, add the following code:

 
<build>  
  <resources>  
    <!-- mapper.xml文件在java目录下 -->
    <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <!-- mapper.xml文件在resources目录下--> <--<resource> <directory>src/main/resources</directory> </resource>--> </resources> </build>

 

Guess you like

Origin www.cnblogs.com/exmyth/p/11184271.html