简体   繁体   English

如何配置Tomcat(Catalina)重新部署Web应用程序而无需重新启动服务器?

[英]How to configutre Tomcat (Catalina) to redeploy web app without restarting server?

Every time I am trying to redeploy my application without restarting server I receive PermGen error , and when I'am trying to close server I receive: 每次我尝试重新部署应用程序而不重新启动服务器时,都会收到PermGen error ,并且在尝试关闭服务器时,我收到:

Java HotSpot(TM) 64-Bit Server VM warning: Exception java.lang.OutOfMemoryError occurred dispatching signal UNKNOWN to handler- the VM may need to be forcibly terminated.

Edit 1: 编辑1:

Sorry, forgot to add my java code. 抱歉,忘记添加我的Java代码。 Here I am using Hibernate + Spring (WebApplicationInitializer), and the error apear only when I am using it. 在这里,我使用的是Hibernate + Spring(WebApplicationInitializer),并且只有在使用时才会出现错误。

package spring2;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller("mainControler")
public class Controll {

    @Autowired
    @Qualifier("personValidator")
    Validator validator;
    private Configuration conf;
    private SessionFactory factory;
    private Session session;
    private Transaction transaction;

    public Controll() {
        // TODO Auto-generated constructor stub
        conf = new Configuration();
        conf.configure("hibernate.cfg.xml");

    }

    @RequestMapping("/")
    public String hello() {
        return "hello";
    }


    //Initiation of the model Person
    @ModelAttribute("person")
    public Person createPersonModel() {
        return new Person();
    }

    //Bind validator to the web app data
    @InitBinder
    public void initBinder(WebDataBinder bind) {
        bind.setValidator(validator);
    }

    @RequestMapping(value="/setPerson", method=RequestMethod.POST)
    public String setPerson(@ModelAttribute("person") @Validated Person person, BindingResult res, Model model) {
        if(!res.hasErrors()) {
            model.addAttribute("success", "Successfully added name and surname");

            setPerson(person);
        }
        return "hello";
    }

    @RequestMapping(value="/setPerson", method=RequestMethod.GET)
    public String setPerson() {
        return hello();
    }

    @RequestMapping(value="/deletePerson", method=RequestMethod.POST)
    public String deletePerson(@ModelAttribute("person") @Validated Person person, BindingResult res, Model model) {
        if(!res.hasErrors()) {
            if(deletePerson(person)) model.addAttribute("success", "Successfuly deleted!");
            else model.addAttribute("success", "Unfortunelly antyty was not deleted");
        }
        return "deleted";
    }

    @RequestMapping(value="/deletePerson", method=RequestMethod.GET)
    public String deletePerson() {
        return "deleted";
    }

    private void setPerson(Person person) {

        factory = conf.buildSessionFactory();
        session = factory.openSession();
        transaction = session.beginTransaction();

        session.persist(person);
        transaction.commit();
        session.close();

    }

    private boolean deletePerson(Person person) {
        factory = conf.buildSessionFactory();

        session = factory.openSession();
        transaction = session.beginTransaction();
//      SQLQuery query = session.createSQLQuery("delete from persons where name= \"" + person.getName() + "\"");
//      query.executeUpdate();
//      Person pers = (Person) session.get(Person.class, person.getId());
        Query query = session.createQuery("from Person as p where p.name like :name").setString("name", "%" + person.getName() + "%");
        List<Person> list = query.list();
        if(list.size() > 0) {
            Person pers1 = list.get(0);
            session.delete(pers1);
            transaction.commit();
            session.close();
            return true;
        }
        return false;

    }
}

Please check the MaxPermSize settings including min and max settings eg:-Xms512M -Xmx756m and try increasing those. 请检查MaxPermSize设置,包括最小和最大设置,例如:-Xms512M -Xmx756m并尝试增加这些设置。 (if its 256 change to 512 etc) (如果它的256变为512等)

if you go to yourTomcatFolder/conf/server.xml 如果您转到yourTomcatFolder/conf/server.xml

And in the <Host> tag you set the attribute autodeploy="true" then the tomcat will redeploy your app without restarting your server. 然后在<Host>标记中设置属性autodeploy="true"则Tomcat将重新部署您的应用程序而无需重新启动服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不重新启动服务器的情况下重新部署EJB项目 - How to redeploy an EJB Project without restarting the server 是否可以在不重新启动服务器的情况下在远程 weblogic 上重新部署应用程序? - Is it possible to redeploy app on remote weblogic without restarting server? 在部署到tomcat服务器的Spring Web应用程序中,catalina.properties文件由spring自动加载和检测。 怎么样? - In Spring web app deployed to tomcat server, catalina.properties file is automatically loaded and detected by spring. HOW? 如何在没有重启服务器的情况下将EAR文件重新部署到Web-Logic? - How to redeploy EAR file to Web-Logic without restart server? 无需重新启动服务器即可部署到tomcat7 - Deploy To tomcat7 without restarting server Tomcat memory 清理而不重启服务器 - Tomcat memory clean without restarting the server 在不重启的情况下将应用程序部署/重新部署到Tomcat的过程 - Pitfals of deploying/redploying app to Tomcat without restarting 如何在不删除/取消部署旧应用程序的情况下在tomcat中重新部署war文件? - How to redeploy war file in tomcat without deleting/undeploy the old application? 如何在不影响Tomcat的情况下替换已编译jar中的文件 - How to replace file in compiled jar without affectig Tomcat redeploy Log4j每天滚动catalina.out而不重启Tomcat? - Log4j daily rolling catalina.out without restarting Tomcat?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM