問題背景:新建了一個maven項目,打了一個可運行jar包,依賴了spring幾個jar包,一跑就報錯了
E:\workspace\point-circle\target>java -jar point-circle-0.0.1-SNAPSHOT.jar 一月 26, 2018 7:44:02 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@31cefde0: startup date [Fri Jan 26 19:44:02 CST 2018]; root of context hierarchy 一月 26, 2018 7:44:02 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [spring-core.xml] Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context] Offending resource: class path resource [spring-core.xml]
問題定位和解決:開始一看,以為是加載配置文件spring-core.xml時路徑不對,結果路徑改了沒用,問題一直在,仔細一看,貌似是命名空間(schema namespace)的問題,想起來之前用maven-shade-plugin插件打可運行包時,沒有注意spring幾個依賴包之間的配置文件沖突問題,給pom.xml再加上spring.schemas等幾個transformer節點試試
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.inspur.chinanet</groupId> <artifactId>point-circle</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>point-circle</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.12.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.3.12.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.12.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.3.12.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.3.12.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.3.12.RELEASE</version> </dependency> <dependency> <groupId>com.vividsolutions</groupId> <artifactId>jts</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId> <version>10.2.0.2.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.inspur.chinanet.point.App</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.tooling</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
右擊項目,選擇Maven,點擊彈出來的Update Project,再次執行maven打包命令,進入生成的jar路徑下跑了一下
E:\>cd workspace\point-circle\target E:\workspace\point-circle\target>java -jar point-circle-0.0.1-SNAPSHOT.jar 一月 26, 2018 7:48:53 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@31cefde0: startup date [Fri Jan 26 19:48:53 CST 2018]; root of context hierarchy 一月 26, 2018 7:48:53 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [spring-core.xml] 一月 26, 2018 7:48:54 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] 一月 26, 2018 7:48:54 下午 org.springframework.jdbc.support.SQLErrorCodesFactory <init> 信息: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana] StatementCallback; bad SQL grammar [select OID,LOCA_TION from ORDER_2I_NEW]; nested exception is java.sql.SQLException: ORA-00942: 表或視圖不存在
這次不再報命名空間問題,已經加載到spring-core.xml鏈接到數據庫了,只不過還沒建表而報錯,問題解決。
