GVKun编程网logo

在tomcat上更改Spring MVC应用程序的应用程序根(springmvc tomcat配置)

24

以上就是给各位分享在tomcat上更改SpringMVC应用程序的应用程序根,其中也会对springmvctomcat配置进行解释,同时本文还将给你拓展android–为现有的SpringMVC应用程

以上就是给各位分享在tomcat上更改Spring MVC应用程序的应用程序根,其中也会对springmvc tomcat配置进行解释,同时本文还将给你拓展android – 为现有的Spring MVC应用程序设计移动应用程序(Spring Mobile或Phonegap)、asp.net-mvc – HttpCache vs Singleton – MVC应用程序的最佳实践、java – JVM Tomcat Spring MVC应用程序超时等待连接池、java – 我的Angular Spring应用程序路由在TomCat上部署时不起作用等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

在tomcat上更改Spring MVC应用程序的应用程序根(springmvc tomcat配置)

在tomcat上更改Spring MVC应用程序的应用程序根(springmvc tomcat配置)

我正在使用Spring MVC 3.0上的示例RESTEasy
2.0资源并依赖于Tomcat6。我可以通过http://localhost:8080/examples-
resteasy-2.1-SNAPSHOT/contacts来获取资源,但是我想通过http:// localhost:8080 /
contacts甚至http:// localhost:8080 / myservice / contacts

我的应用程序映射到路径的方式是否需要更改?

Web.xml

<web-app>    <servlet>        <servlet-name>springmvc</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>classpath:springmvc-servlet.xml</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>springmvc</servlet-name>        <url-pattern>/contacts/*</url-pattern>    </servlet-mapping></web-app>

springmvc-servlet.xml

<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"    xsi:schemaLocation="        http: //www.springframework.org/schema/context http: //www.springframework.org/schema/context/spring-context-3.0.xsd        http: //www.springframework.org/schema/beans http: //www.springframework.org/schema/beans/spring-beans.xsd    ">    <context:component-scan base-package="org.jboss.resteasy.examples.springmvc" />    <context:annotation-config />    <import resource="classpath:springmvc-resteasy.xml" />  <!-- this is included in the resteasy-spring library-->    <bean id="viewResolver">        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />        <property name="prefix" value="/WEB-INF/" />        <property name="suffix" value=".jsp" />    </bean></beans>

我的RESTEasy资源类别

@Controller@Path("/contacts")public class ContactsResource {...

答案1

小编典典

您可以在Tomcat server.xml中进行设置。

<Context><Host>下面的类似图中添加一个元素,将您设置examples-resteasy-2.1-SNAPSHOT为默认Web应用程序。

<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="" reloadable="true" />

这应该允许您以http:// localhost:8080 / contacts访问它

将路径设置为“ myservice”,如下所示

<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="/myservice" reloadable="true" />

应该允许您以http:// localhost:8080 / myservice / contacts访问它

android – 为现有的Spring MVC应用程序设计移动应用程序(Spring Mobile或Phonegap)

android – 为现有的Spring MVC应用程序设计移动应用程序(Spring Mobile或Phonegap)

我使用 Spring MVC和 MySQL在Openshift上创建了一个Web应用程序.

现在我想为这个应用程序移动.我想将相同的应用程序发布为移动应用程序(主要是Android).首先,这个移动版本也应该使用HttpPost / Webservice安全授权.

我知道Pivotal有一个Spring Mobile项目,它可以为同一个应用程序创建一个移动站点(比如spring form标签和所有应用程序更复杂).

另一方面,Phonegap可以借助HTML5和CSS创建一个跨平台的移动应用程序.

我的问题是:

>将我的精力放在Phonegap或Spring Mobile上是否值得?
>如果我选择Spring Mobile,如何在Android Play商店中发布移动应用程序?

一些利弊或任何参考链接将有所帮助.

解决方法

介绍

首先,让我给你一个警告.虽然这是一个建设性的问题(比这里提到的平均问题更好),但人们通常喜欢那些花费一些时间自己寻找答案的用户的问题.我稍后会解释这一部分.

差异

Phonegap(Cordova)和Spring Mobile是两个完全不同的框架,它们提供完全不同的用途.你可能已经发现谷歌搜索.

Phonegap(Cordova)是一个用于混合移动应用程序创建的包装框架.您的HTML / CSS / JavaScript代码已封装到本机shell中,您可以使用JavaScript< - >用于访问本机电话功能的本机桥接代码.虽然您可以像使用vanilla JavaScript一样使用它,但它通常与其他移动框架一起使用,如jQuery Mobile,Sencha Touch或Kendo UI.

Spring Mobile是Spring MVC的扩展,旨在简化移动Web应用程序的开发. Spring Mobile是一个框架,它提供了检测向Spring网站发出请求的设备类型的功能,并根据该设备提供备用视图.

功夫

一切都取决于你要做什么.混合移动应用程序通常使用单独的客户端和服务器端代码完成.使用AJAX完成通信.因此我会跳过Spring Mobile并仅使用Spring作为RESTful Web服务框架.我个人更喜欢Play框架,但那只是我.

当然,您仍然需要选择客户端JavaScript框架,或者您可以从头开始创建所有内容.我建议你使用像jQuery Mobile这样的预构建框架.

如果你真的想要使用Spring Mobile

如果你真的想使用Spring Mobile,它仍然可以完成. Phonegap可用于将远程网站包装到移动应用程序中.这种方法有几个缺点.如果您的网站停机并且您将无法创建iOS应用程序,则该应用程序将无用,因为这些类型的应用程序一见钟面就被拒绝了.

最佳行动方案

>单独的客户端和服务器端代码
>选择a client side mobile JavaScript framework.
>使用Spring作为RESTful Web服务,或任何其他RESTful框架,如Play.
>将客户端代码包装到Phonegap(Cordova)
>发布为Android,iPhone应用程序

链接

>如何create jQuery Mobile application with Phonegap | Mac version
> Sencha Touch vs jQuery Mobile
> Secrets of a good jQuery Mobile page architecture
>如果您已经有过jQuery的经验,learn the differences between jQuery and jQuery Mobile

asp.net-mvc – HttpCache vs Singleton – MVC应用程序的最佳实践

asp.net-mvc – HttpCache vs Singleton – MVC应用程序的最佳实践

我对HttpCache和Singleton方法的理解有点困惑.

我的应用程序使用Asp.net MVC,方案是,我有一些永远不会改变的数据列表和一些可能很少改变的数据.

我已经使用Singleton存储库为这种类型的数据开发和部署了应用程序.
它表现很好.唯一的问题是,当罕见的情况发生时,我必须重新启动IIS才能生效.

什么是最好的解决方案.

单身实施

public class SingletonRepository : ISingletonRepository
    {
        private static SingletonRepository singleInstance;

        private readonly IStateRepository stateRepo;
        private readonly ICountryRepository countryRepo;
        private readonly ITDPaymentModeRepository paymentModeRepo;
        private readonly ITdplanRepository planRepo;
        private readonly ITDOrderTypeRepository orderTypeRepo;
        private readonly IKeywordRepository keywordRepo;
        private readonly IAgencyRepository agencyRepo;

        private readonly IList<AT_STATE> lstState;
        private readonly IList<AT_COUNTRY> lstCountry;
        private readonly IList<TDPaymentMode> lstPaymentMode;
        private readonly IList<Tdplan> lstPlan;
        private readonly IList<TDOrderType> lstOrderType;
        private readonly IList<Keyword> lstKeyword;
        private readonly IList<Agency_MST> lstAgency;

        private SingletonRepository()
        {
            stateRepo = new StateRepository();
            countryRepo = new CountryRepository();
            paymentModeRepo = new TDPaymentModeRepository();
            planRepo = new TdplanRepository();
            orderTypeRepo = new TDOrderTypeRepository();
            keywordRepo = new KeywordRepository();
            agencyRepo = new AgencyRepository();

            lstState = stateRepo.GetAll().Where(x => x.CountryId == 101).ToList();
            lstCountry = countryRepo.GetAll().ToList();
            lstPaymentMode = paymentModeRepo.GetAll().ToList();
            lstPlan = planRepo.GetAll().ToList();
            lstOrderType = orderTypeRepo.GetAll().ToList();
            lstKeyword = keywordRepo.GetAll().ToList();
            lstAgency = agencyRepo.GetAll().ToList();

            //lstState = stateRepo.GetAll().Take(20).ToList();
            //lstCountry = countryRepo.GetAll().Take(20).ToList();
            //lstPaymentMode = paymentModeRepo.GetAll().Take(20).ToList();
            //lstPlan = planRepo.GetAll().Take(20).ToList();
            //lstOrderType = orderTypeRepo.GetAll().Take(20).ToList();
            //lstKeyword = keywordRepo.GetAll().Take(20).ToList();
            //lstAgency = agencyRepo.GetAll().Take(20).ToList();
        }

        public static SingletonRepository Instance()
        {
            return singleInstance ?? (singleInstance = new SingletonRepository());
        }

        public IList<AT_STATE> GetState()
        {
            return this.lstState;
        }
        public IList<AT_COUNTRY> GetCountry()
        {
            return this.lstCountry;
        }

        public IList<TDPaymentMode> GetPaymentMode()
        {
            return this.lstPaymentMode;
        }

        public IList<Tdplan> GetPlan()
        {
            return this.lstPlan;
        }

        public IList<TDOrderType> GetorderType()
        {
            return this.lstOrderType;
        }

        public IList<Keyword> GetKeyword()
        {
            return this.lstKeyword;
        }

        public IList<Agency_MST> GetAgency()
        {
            return this.lstAgency;
        }      

    }

}

解决方法

使用单例模式的目的通常不是静态数据存储.当您只希望一个对象实例能够执行某些操作时,您应该使用单例.它可能很快,但正如您所看到的,当数据发生变化时,您需要重置堆以获取新数据(如您所说,通过重新启动IIS).

HttpCache(更具体地说,Http缓存默认使用的ObjectCache)将数据存储在与堆相同的位置:在随机存取存储器中.因此,它与存储在堆上的类或实例中的静态数据一样快.不同之处在于您可以将缓存设置为定期过时,以便在数据更改时获取新数据.您甚至可以设置sqlCacheDependencies,以便在数据库状态发生更改时使缓存失效.

缓存的另一个优点是它可以更有效地利用服务器的RAM资源.使用您的单例,无论如何,即使数据未被使用,这些数据也将始终占用内存.使用缓存时,服务器仅在使用时将数据存储在内存中.缓存的缺点是偶尔,用户在缓存过期后请求数据时会得到较慢的响应.但是,在他们这样做之后,其他用户将受益于缓存一段时间的数据.

java – JVM Tomcat Spring MVC应用程序超时等待连接池

java – JVM Tomcat Spring MVC应用程序超时等待连接池

我在tomcat上运行的 spring应用程序打开了很多与localhost的连接,如下所示:

tcp6       1      0 localhost:4431          localhost:44178         CLOSE_WAIT  2393/java       
tcp6       1      0 localhost:4431          localhost:44279         CLOSE_WAIT  2393/java       
tcp6       1      0 localhost:4431          localhost:44264         CLOSE_WAIT  2393/java       
tcp6       1      0 localhost:4431          localhost:44160         CLOSE_WAIT  2393/java       
tcp6       1      0 localhost:4431          localhost:44224         CLOSE_WAIT  2393/java

并导致超时等待连接池.

你知道连接是什么吗?

我的server.xml看起来像这样:

<?xml version='1.0' encoding='utf-8'?>
    <Server port="8005" shutdown="SHUTDOWN">
      <Listener className="org.apache.catalina.core.JasperListener" />
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
      <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
      <Realm className="org.apache.catalina.realm.MemoryRealm" />
      <GlobalNamingResources>
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>
      <Service name="Catalina">
        <Connector  port="8080" protocol="HTTP/1.1"
                    compression="on"
                    compressionMinSize="2048"
                    noCompressionUserAgents="gozilla,traviata"
                    compressableMimeType="
                        text/html,text/xml,text/plain,text/css,text/javascript,text/json,application/x-javascript,application/javascript,application/json,application/x-font-woff,image/png,image/jpeg,image/gif,image/svg+xml
                    " 
                    connectionTimeout="20000"
                    URIEncoding="UTF-8"
                    maxThreads="10000"
                    maxConnections="-1"
                    redirectPort="4431" />
        <Connector  port="4431" protocol="HTTP/1.1"
                    compression="on"
                    compressionMinSize="2048"
                    noCompressionUserAgents="gozilla,image/svg+xml
                    "
                    connectionTimeout="20000"
                    URIEncoding="UTF-8"
                    maxThreads="10000"
                    maxConnections="-1"
                    scheme="https"
                    secure="true"
                    clientAuth="false"
                    proxyPort="443" />
        <Engine name="Catalina" defaultHost="localhost">
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          <Realm className="org.apache.catalina.realm.LockOutRealm">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
          </Realm>
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log." suffix=".txt"
                   pattern="%h %A %u %t &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" />
          </Host>
        </Engine>
      </Service>
    </Server>

端口4431是主连接器的端口.似乎应用程序调用自己.

解决方法

看来你的SSL配置没有以tomcat结尾,那么你可以完全删除4431端口的连接器,并用proxyPort =“443”替换8080连接器的redirectPort属性

java – 我的Angular Spring应用程序路由在TomCat上部署时不起作用

java – 我的Angular Spring应用程序路由在TomCat上部署时不起作用

我非常喜欢棱角分明和弹簧.我可能犯了一些愚蠢的错误.
我有Angular Spring应用程序,它显示登录屏幕,然后显示菜单.
未部署时(即当Angular& Spring并行运行时),这种方法非常有效
但是当我在tomcat上部署应用程序时,它不会显示登录表单.
我按照以下步骤进行部署 –

> ng build –base-href =./
>将angular dist文件夹中的所有文件复制到spring静态文件夹
>在spring中创建.war文件并将其部署在tomcat中

我的pom.xml

<groupId>com.techence</groupId>
        <artifactId>new</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>

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

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.4.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>
        </properties>

        <dependencies>

        <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>MysqL</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>


            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>

                <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <version>1.5.7.RELEASE</version>
                <scope>provided</scope>
                </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

            <dependency>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <type>maven-plugin</type>
            </dependency>
        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>


        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                    <version>2.4</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>

我的app.module.ts

import { browserModule } from ''@angular/platform-browser'';
import { NgModule } from ''@angular/core'';
import { AppComponent } from ''./app.component'';
import { LoginFormComponent } from ''./login-form/login-form.component'';
import { HttpModule } from ''@angular/http'';
import { FormsModule} from ''@angular/forms'';
import { LoginServiceService } from ''./login-service.service'';
import { HttpClientModule } from ''@angular/common/http'';
import { MenubarComponent } from ''./menubar/menubar.component'';
import { BranchCreationComponent } from ''./menubar/branch-creation/branch-
creation.component'';
import { RouterModule,Routes } from ''@angular/router'';
import { LedgerCreationComponent } from ''./menubar/ledger-creation/ledger-creation.component'';

import { LocationStrategy } from ''@angular/common'';

import { HashLocationStrategy } from ''@angular/common'';

import { ForgotPasswordComponent } from ''./forgot-password/forgot-
password.component'';

const routes: Routes = [    
    { path: '''', component : LoginFormComponent}, 

    { path: ''menubar'', component: MenubarComponent }, 

    { path: ''branchCreation'', component: BranchCreationComponent },

    { path: ''ledgerCreation'', component: LedgerCreationComponent } 
];

@NgModule({
declarations: [

    AppComponent,

    LoginFormComponent,

    MenubarComponent,

    BranchCreationComponent,

    LedgerCreationComponent,

    ForgotPasswordComponent

  ],
  imports: [ 
    browserModule,

FormsModule,

HttpModule,

HttpClientModule,

RouterModule.forRoot(routes),

  ],


  providers: [
              LoginServiceService,
             { provide: LocationStrategy, useClass: HashLocationStrategy },
            ],
  bootstrap: [AppComponent]
})
export class AppModule { }

解决方法:

尝试在Spring Boot代码中添加:

@Bean
public ErrorViewResolver customErrorViewResolver() {
    final ModelAndView redirectToIndexHtml = new ModelAndView("forward:/index.html", Collections.emptyMap(), HttpStatus.OK);
    return (request, status, model) -> status == HttpStatus.NOT_FOUND ? redirectToIndexHtml : null;
}

它适用于我,甚至Angular路由工作.我发现它here.

总结

以上是小编为你收集整理的java – 我的Angular Spring应用程序路由在TomCat上部署时不起作用全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

原文地址:https://codeday.me/bug/20191003/1849020.html

今天关于在tomcat上更改Spring MVC应用程序的应用程序根springmvc tomcat配置的讲解已经结束,谢谢您的阅读,如果想了解更多关于android – 为现有的Spring MVC应用程序设计移动应用程序(Spring Mobile或Phonegap)、asp.net-mvc – HttpCache vs Singleton – MVC应用程序的最佳实践、java – JVM Tomcat Spring MVC应用程序超时等待连接池、java – 我的Angular Spring应用程序路由在TomCat上部署时不起作用的相关知识,请在本站搜索。

本文标签: