我将我的spring mvc app迁移到了spring boot。它现在作为独立运行良好,只要我将包装留给战争。 当我只将包装更改为jar时,应用程序会为任何页面提供404。显然它没有找到资源。为什么呢?
Project
-src
--main
---java
---resources
---webapp
----pages <-- here are my pages
我的pom
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.tki.webapp.weasy</groupId>
<artifactId>weasy</artifactId>
<packaging>war</packaging>
<version>1.1-SNAPSHOT</version>
<name>Weasy</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://gitserver:8082/nexus/content/groups/public/</url>
</repository>
<repository>
<id>nexus_releases</id>
<name>nexus_releases</name>
<url>http://gitserver:8082/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>jasper-releases</id>
<name>jasper-releases</name>
<url>https://jaspersoft.artifactoryonline.com/jaspersoft/jr-ce-releases/</url>
</repository>
</repositories>
<properties>
<logback.version>1.0.13</logback.version>
<jdk.version>1.7</jdk.version>
<context.path>Weasy</context.path>
</properties>
<developers>
<developer>
<id>...</id>
<email>...</email>
<organization>...</organization>
<organizationUrl>...</organizationUrl>
<roles>
<role>Java Developer</role>
</roles>
<timezone>+5:30</timezone>
</developer>
</developers>
<build>
<finalName>${pom.artifactId}-${project.version}</finalName>
<!-- <finalName>$\{project.artifactId}-$\{project.version}-r$\{buildNumber}</finalName> -->
<plugins>
<!-- Maven compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin> -->
<!-- <groupId>com.github.wvengen</groupId> -->
<!-- <artifactId>proguard-maven-plugin</artifactId> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <phase>package</phase> -->
<!-- <goals> -->
<!-- <goal>proguard</goal> -->
<!-- </goals> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- <configuration> -->
<!-- <obfuscate>true</obfuscate> -->
<!-- <injar>${project.build.finalName}</injar> -->
<!-- <outjar>${project.build.finalName}-small.jar</outjar> -->
<!-- <outputDirectory>${project.build.directory}</outputDirectory> -->
<!-- <options> -->
<!-- <option>-optimizations !class/marking/final</option> -->
<!-- <option>-adaptresourcefilecontents -->
<!-- **.properties,META-INF/MANIFEST.MF,META-INF/spring.*</option> -->
<!-- <option>-keepattributes -->
<!-- Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option> -->
<!-- <option>-keepclasseswithmembers public class * { public static -->
<!-- void main(java.lang.String[]);}</option> -->
<!-- <option>-keepclassmembers class * { -->
<!-- @org.springframework.beans.factory.annotation.Autowired *; -->
<!-- @org.springframework.beans.factory.annotation.Value *; -->
<!-- } -->
<!-- </option> -->
<!-- <option>-keep public class org.foo.**</option> -->
<!-- <option>-keep public class org.springframework.**</option> -->
<!-- <option>-ignorewarnings</option> -->
<!-- </options> -->
<!-- <libs> -->
<!-- <lib>${java.home}/lib/rt.jar</lib> -->
<!-- </libs> -->
<!-- <injarNotExistsSkip>true</injarNotExistsSkip> -->
<!-- </configuration> -->
<!-- <dependencies> -->
<!-- <dependency> -->
<!-- <groupId>net.sf.proguard</groupId> -->
<!-- <artifactId>proguard-base</artifactId> -->
<!-- <version>5.2.1</version> -->
<!-- <scope>runtime</scope> -->
<!-- </dependency> -->
<!-- </dependencies> -->
<!-- </plugin> -->
</plugins>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<!-- this must be installed into local reposotory (SqlServer jdbc) -->
<dependency>
<groupId>jdbc</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4</version>
</dependency>
<!-- this must be installed into local reposotory (Oracle jdbc) -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>1.0</version>
</dependency>
<!-- for json deserialisation -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<!-- Apache Commons Upload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Apache Commons Upload -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- dependency for jasperreports which is not on maven central -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-functions</artifactId>
<version>6.1.0</version>
<scope>provided</scope>
</dependency>
<!-- dependency for jasperreports -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>de.tki.hbci</groupId>
<artifactId>jfints</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</project>
正如您在我的Application类中看到的,我从spring.xml迁移。这会导致问题吗?
@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
@ImportResource("classpath:spring-config.xml")
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
spring-config.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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- <bean class="de.tki.webapp.util.HyperSqlDbServer" id="hsqldb" -->
<!-- init-method="start" destroy-method="stop"> -->
<!-- <constructor-arg> -->
<!-- <value> -->
<!-- server.database.0=${database.file} -->
<!-- server.dbname.0=${database.service} -->
<!-- server.remote_open=true -->
<!-- hsqldb.reconfig_logging=false -->
<!-- </value> -->
<!-- </constructor-arg> -->
<!-- </bean> -->
<context:component-scan base-package="de.tki.webapp.controller" />
<context:property-placeholder location="classpath:database.properties" />
<bean id="defaults"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:defaults.properties</value>
</list>
</property>
</bean>
<mvc:annotation-driven />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>de.tki.webapp.domain.Column</value>
<value>de.tki.webapp.domain.BusinessCase</value>
<value>de.tki.webapp.domain.Connection</value>
<value>de.tki.webapp.domain.LogBcLoad</value>
<value>de.tki.webapp.domain.LogTableLoad</value>
<value>de.tki.webapp.domain.Link</value>
<value>de.tki.webapp.domain.Source</value>
<value>de.tki.webapp.domain.SrcSchema</value>
<value>de.tki.webapp.domain.SrcTable</value>
<value>de.tki.webapp.domain.Preference</value>
<value>de.tki.webapp.domain.Preferences</value>
<value>de.tki.webapp.domain.TypeReplacement</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="hibernate.event.merge.entity_copy_observer">allow</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000000"/>
</bean>
<!-- Auto scan the components -->
<context:component-scan base-package="de.tki.webapp.domain" />
<context:component-scan base-package="de.tki.webapp.services" />
<context:component-scan base-package="de.tki.webapp.services.report" />
<context:component-scan base-package="de.tki.webapp.dao" />
<context:component-scan base-package="de.tki.webapp.dao.report" />
<context:component-scan base-package="de.tki.webapp.controller" />
<context:component-scan base-package="de.tki.webapp.controller.report" />
<context:component-scan base-package="de.tki.webapp.reconcile" />
<context:component-scan base-package="de.tki.webapp.generator" />
<context:component-scan base-package="de.tki.webapp.dbclient" />
<context:component-scan base-package="de.tki.webapp.util" />
<mvc:resources mapping="/resources/**" location="/resources/theme1/" />
</beans>