Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何让Spring使用WildFly而不是Tomcat?_Java_Spring_Maven_Tomcat - Fatal编程技术网

Java 如何让Spring使用WildFly而不是Tomcat?

Java 如何让Spring使用WildFly而不是Tomcat?,java,spring,maven,tomcat,Java,Spring,Maven,Tomcat,我试图实现JSR注释来处理缓存。经过大量的研究和几个问题之后,我得出了下面的观点。当我试着运行它时,它说 java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer Caused by: java.

我试图实现JSR注释来处理缓存。经过大量的研究和几个问题之后,我得出了下面的观点。当我试着运行它时,它说

java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer Caused by: java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer Caused by: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer"}}
我做错了什么

HelloService.java

@Path("/helloservice")
@EnableCaching
public class HelloService extends CachingSetup{

    @GET
    @Path("/unsecured")
    @Produces({"text/plain"})
    @CacheResult
    public String testUnsecured(){
        return "Unsecured user";
    }
}
CachingSetup.java

import static java.util.concurrent.TimeUnit.SECONDS;
import javax.cache.CacheManager;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.expiry.Duration;
import javax.cache.expiry.TouchedExpiryPolicy;
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
import org.springframework.stereotype.Component;

  @Component
  public class CachingSetup implements JCacheManagerCustomizer
  {
    @Override
    public void customize(CacheManager cacheManager)
    {
      cacheManager.createCache("basicCache", new MutableConfiguration<>()  
        .setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(SECONDS, 10))) 
        .setStoreByValue(false)
        .setStatisticsEnabled(true));
    }
  }
导入静态java.util.concurrent.TimeUnit.SECONDS;
导入javax.cache.CacheManager;
导入javax.cache.configuration.MutableConfiguration;
导入javax.cache.expiry.Duration;
导入javax.cache.expiry.TouchedExpiryPolicy;
导入org.springframework.boot.autoconfigure.cache.jCacheManagerConstomizer;
导入org.springframework.stereotype.Component;
@组成部分
公共类CachingSetup实现JCacheManagerConstomizer
{
@凌驾
公共void自定义(CacheManager CacheManager)
{
createCache(“basicCache”,新的可变配置()
.setExpiryPolicyFactory(触摸ExpiryPolicy.factoryOf(新的持续时间(秒,10)))
.setStoreByValue(错误)
.setStatisticsEnabled(true));
}
}
ehcache.xml

<config
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.ehcache.org/v3'  
    xmlns:jsr107='http://www.ehcache.org/v3/jsr107'>  

  <service>
    <jsr107:defaults>
      <jsr107:cache name="basicCache" template="heap-cache"/> 
    </jsr107:defaults>
  </service>

  <cache-template name="heap-cache">
    <listeners>    
      <listener>
        <class>org.terracotta.ehcache.EventLogger</class>
        <event-firing-mode>ASYNCHRONOUS</event-firing-mode>
        <event-ordering-mode>UNORDERED</event-ordering-mode>
        <events-to-fire-on>CREATED</events-to-fire-on> 
        <events-to-fire-on>UPDATED</events-to-fire-on> 
        <events-to-fire-on>EXPIRED</events-to-fire-on> 
        <events-to-fire-on>REMOVED</events-to-fire-on> 
        <events-to-fire-on>EVICTED</events-to-fire-on> 
      </listener>
    </listeners>
    <resources>
      <heap unit="entries">2000</heap> 
      <offheap unit="MB">100</offheap> 
    </resources>
  </cache-template>
</config>

org.terracotta.ehcache.EventLogger
异步的
无序
创建
更新
期满
远离的
驱逐
2000
100
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.sentiment360</groupId>
    <artifactId>QuteeDemoRest</artifactId>
    <version>v1</version>
    <packaging>war</packaging>

    <name>QuteeDemoRest</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

        <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId> 
      <version>1.3.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>1.5.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>3.0.14.Final</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-links -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-links</artifactId>
            <version>3.1.4.Final</version>
        </dependency> 
        <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.1.4.Final</version>
        </dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxb-provider -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
            <version>1.0-RC1</version>
        </dependency>        
        <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.6.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>3.3.1</version>
        </dependency>

        <dependency>
          <groupId>javax.cache</groupId>
          <artifactId>cache-api</artifactId>
        </dependency>
                      <!--SPRING-->

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-cache</artifactId> 
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId> 
    </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
com.360
qutedemorest
v1
战争
qutedemorest
${project.build.directory}/project
UTF-8
org.springframework.boot
spring启动程序父级
1.3.2.1发布
爪哇
javaeewebapi
7
假如
org.mariadb.jdbc
mariadb java客户端
1.5.5
org.jboss.resteasy
resteasy多部分提供程序
3.0.14.1最终版本
假如
org.jboss.resteasy
轻松链接
3.1.4.最终版本
org.jboss.resteasy
resteasy jaxrs
3.1.4.最终版本
org.jboss.resteasy
resteasy jaxb提供程序
1.0-RC1
io.jsonwebtoken
jjwt
0.6.0
org.ehcache
ehcache
3.3.1
javax.cache
缓存api
org.springframework.boot
springbootstarter缓存
org.springframework.boot
SpringBootStarterWeb
org.apache.maven.plugins
maven编译器插件
3.1
1.7
1.7
${annowed.dir}
org.apache.maven.plugins
maven战争插件
2.3
假的
org.apache.maven.plugins
maven依赖插件
2.6
验证
复制
${annowed.dir}
真的
爪哇
javaee认可的api
7
罐子

多亏了上面@R.C.的链接,我发现我需要修改pom.xml以删除默认的Spring tomcat实现

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId> 
</dependency>

org.springframework.boot
SpringBootStarterWeb
需要:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId> 

<exclusions>
    <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
</exclusions>
</dependency>

org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
我还补充说

<packaging>war</packaging>
战争
在顶部版本标签的正下方,使其看起来像:

<groupId>com.sentiment360</groupId>
<artifactId>QuteeDemoRest</artifactId>
<version>v1</version>
<packaging>war</packaging>

<name>QuteeDemoRest</name>
com.360
qutedemorest
v1
战争
qutedemorest

你看到了吗?谢谢你的链接-我正在深入研究它