Liberty概要文件无法检测Spring Boot组件的注释而不能加载应用程序上下文

时间:2016-12-31 06:03:30

标签: spring-boot websphere-liberty

我正在Liberty 16.0.0.3中部署Spring Boot Web应用程序.Have提供了所有依赖范围作为提供和配置的全局共享库。但是当我启动应用程序时,Liberty无法加载应用程序上下文。

我的配置如下。

我的pom.xml

var ConnectedTransitionGroup = connect(
  store => ({
   transitionState: state.transitions
  }),
  dispatch => ({ dispatch })
)(TransitionGroup)

render() {
  return (
    <ConnectedTransitionGroup childFactory={childFactory}>
      {children}
    </ConnectedTransitionGroup>
  )
}

Liberty server.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.myapp.testapp</groupId>
    <artifactId>testsharedlib</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>testsharedlib</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <runtime.scope>provided</runtime.scope>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>${runtime.scope}</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-ws</artifactId>
            <scope>${runtime.scope}</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>



    <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!-- <version>2.3</version> -->
            <executions>
               <execution>
                  <goals>
                     <goal>repackage</goal>
                  </goals>
                  <configuration>
                     <skip>true</skip>
                     <!-- <failOnMissingWebXml>false</failOnMissingWebXml> -->
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                    <archive>
                        <manifest>
                            <mainClass>com.myapp.testapp.Appconfig</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                        <manifestEntries>
                            <DisableIBMJAXWSEngine>true</DisableIBMJAXWSEngine>
                            <Class-Path>conf</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

         <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

         <plugin>
            <artifactId>maven-resources-plugin</artifactId>
         </plugin>
      </plugins>
   </build>


</project>

2 个答案:

答案 0 :(得分:1)

我可以通过在Liberty中提供WEB-INF/web.xml全局共享库来使其工作。查找以下示例配置。

<强>的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.myapp.testapp</groupId>
    <artifactId>testsharedlib</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>testsharedlib</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <runtime.scope>provided</runtime.scope>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>${runtime.scope}</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-ws</artifactId>
            <scope>${runtime.scope}</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
<build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
               <execution>
                  <goals>
                     <goal>repackage</goal>
                  </goals>
                  <configuration>
                     <skip>true</skip>
                  </configuration>
               </execution>
            </executions>
         </plugin>

         <plugin>
            <artifactId>maven-resources-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
</project>

<强> server.xml中

    <featureManager>
    <feature>webProfile-7.0</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>


   <library id="global">
        <fileset dir="${server.config.dir}/lib/jars" includes="*.jar"/>
    </library>

    <application context-root="HelloWorld" location="text-1.0.0-SNAPSHOT.war">
        <classloader commonLibraryRef="global" delegation="parentLast"/>
    </application>

   <!-- Define the host name for use by the collective.
        If the host name needs to be changed, the server should be
        removed from the collective and re-joined. -->
   <variable name="defaultHostName" value="localhost"/>

   <keyStore id="defaultKeyStore" password="adminpwd"/>

    <!-- Define an Administrator and non-Administrator -->
   <basicRegistry id="basic">
      <user name="admin" password="adminpwd"/>
      <user name="nonadmin" password="nonadminpwd"/>
   </basicRegistry>

   <!-- Assign 'admin' to Administrator -->
   <administrator-role>
      <user>admin</user>
   </administrator-role>

   <webContainer deferServletLoad="false"/>
   <applicationManager autoExpand="true"/>

    <httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <logging consoleLogLevel="INFO" traceSpecification="*=info:com.ibm.ws.classloading.*=ALL"/>

</server>

<强>的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

 <display-name>pctext</display-name>

 <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>com.myapp.testpkg.ApplicationConfig</param-value>
        </init-param>
    <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
 </servlet-mapping>

</web-app>

<强> ApplicationConfig.java

@SpringBootApplication(scanBasePackages={"com.myapp.testpkg"})

public class ApplicationConfig {
  public static void main(String[] args) {      
    SpringApplication.run(ApplicationConfig.class, args);
  }
}

答案 1 :(得分:1)

这与*.sp*中的依赖关系而不是全局共享库中的依赖关系的原因是因为初始化Spring应用程序(WEB-INF/lib)的servlet来自其中一个jar依赖项。 Liberty将仅扫描servlet类的Web上下文根(即org.springframework.web.servlet.DispatcherServlet)。它不会扫描servlet类的共享库。

正如您在其他答案中发现的那样,链接来自共享库中的jar的servlet的唯一方法是在web.xml中显式声明它(因为Liberty不会像它一样自动扫描它适用于WEB-INF/*中的课程或专业证书。

为了证实这一点,我写了一个简单的servlet:

WEB-INF/*

然后我将这个servlet打包到@WebServlet("/LibServlet") public class LibServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().append("Served at: ").append(request.getContextPath()); } } 。当我使用共享库将此lib提供给我的应用程序时,我无法访问servletLib.jar处的servlet。但是,当我将http://localhost:9080/testapp/LibServlet移动到servletLib.jar时,可以访问servlet。