如何将 Guice Persist (Guice 3.0) 与 Wicket 1.5 一起使用?

发布于 2024-12-12 03:34:39 字数 13135 浏览 0 评论 0原文

我想了解如何将 Guice Persist (Guice 3.0) 与 Wicket 1.5 一起使用。

我无法找到任何“hello world”类型的示例来解释如何执行此操作,如果您可以链接/提供这样一个示例,那就太好了,并且很高兴地接受作为答案。

与此同时,我将尝试自己创建一个“hello world”类型的示例,并在进展过程中将代码发布到此处。帮助我的代码正常运行也将被接受作为答案。


我已经建立了一个简单的 wicket 项目,与 Wicket Examples 中的“hello world”guice 示例非常相似,使用 guice 进行依赖注入。我现在想扩展这个项目以也使用 JPA 和 Guice Persist,而不是“Hello World”,我想从数据库中获取用户并显示其用户名。我正在尝试使用 Guice wiki 中有关 Guice persist。

更新:所以,我有点让它工作了。在 WebApplication.init() 中,我注入了一个像这样的 ServetModule getComponentInstantiationListeners().add(new GuiceComponentInjector(this, new MyServletModule())); 并且我还在以下位置添加了 GuiceFilter web.xml 文件的顶部,在 wickets 过滤器之前。

现在,当我运行应用程序时,一切正常,但我收到有关使用已弃用的方法的警告。将进一步研究这一点。

警告:您正在尝试使用已弃用的 API(具体来说, 尝试在急切创建的内部@Inject ServletContext 单例。虽然我们允许这样做是为了向后兼容,但请注意 如果您有多个,这可能会出现意外行为 注入器(带有 ServletModule)在同一个 JVM 中运行。请咨询 Guice 文档位于 http://code.google.com/p/google-guice/wiki/Servlets 了解更多 信息。

目录树

.
├── pom.xml
└── src
    └── main
        ├── java
        │   └── se
        │       └── lil
        │           ├── HomePage.html
        │           ├── HomePage.java
        │           ├── MyServletModule.java
        │           ├── WicketApplication.java
        │           ├── domain
        │           │   └── User.java
        │           └── service
        │               ├── IService.java
        │               └── JpaService.java
        ├── resources
        │   ├── META-INF
        │   │   └── persistence.xml
        │   └── log4j.properties
        └── webapp
            └── WEB-INF
                └── web.xml

WicketApplication.java

public class WicketApplication extends WebApplication {
    @Override
    protected void init() {
        super.init();
        getComponentInstantiationListeners().add(new GuiceComponentInjector(this,
                new MyServletModule()));
    }

    @Override
    public Class<? extends Page> getHomePage() {
        return se.lil.HomePage.class;
    }
}

HomePage.java

public class HomePage extends WebPage {
    private static final long serialVersionUID = -918138816287955837L;

    @Inject
    private IService service;

    private IModel<User> model = new LoadableDetachableModel<User>() {
        private static final long serialVersionUID = 1913317225318224531L;

        @Override
        protected User load() {
            return service.getUser();
        }
    };

    public HomePage() {
        setDefaultModel(new CompoundPropertyModel<User>(model));
        add(new Label("name"));
    }
}

HomePage.html

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:wicket="http://wicket.apache.org">
<head>
<title>Wicket Examples - guice</title>
</head>
<body>
    <hr />
        Value: <b wicket:id="name">name goes here</b> <br />
    <hr />
</body>
</html>

MyServletModule.java

public class MyServletModule extends ServletModule {
    protected void configureServlets() {
        install(new JpaPersistModule("manager1"));
        filter("/*").through(PersistFilter.class);
    }
}

< em>IService.java

@ImplementedBy(JpaService.class)
public interface IService {
    public User getUser();
}

JpaService.java

public class JpaService implements IService {
    @Inject
    private EntityManager em;

    @Override
    @Transactional
    public User getUser() {
        Query q = em.createQuery("FROM User");
        q.setMaxResults(1);
        User u = (User) q.getSingleResult();
        return u;
    }
}

User.java

@Entity
@Table (name = "users")
public class User {
    private Long id;
    private String name;

    public User() {
    }

    public User(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }
    @SuppressWarnings("unused")
    private void setId(Long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }   
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <display-name>wicketwithguice</display-name>

    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>wicket.wicketwithguice</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>se.lil.WicketApplication</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>wicket.wicketwithguice</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>se.lil.domain.User</class> 
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
            <property name="hibernate.show_sql" value="true"/>

            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/test"/>
            <property name="javax.persistence.jdbc.user" value="test"/>
            <property name="javax.persistence.jdbc.password" value="1234"/>
        </properties>
    </persistence-unit>
</persistence>

< em>pom.xml

<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>se.lil</groupId>
    <artifactId>wicketwithquice</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <!-- TODO project name -->
    <name>quickstart</name>
    <description></description>
    <!-- TODO <organization> <name>company name</name> <url>company url</url> </organization> -->

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <hibernate-core.version>3.6.4.Final</hibernate-core.version>
        <mysql-connector-java.version>5.1.16</mysql-connector-java.version>
        <slf4j.version>1.6.1</slf4j.version>
        <log4j.version>1.6.1</log4j.version>
        <guice.version>3.0</guice.version>
        <wicket.version>1.5.2</wicket.version>
    </properties>

    <dependencies>
        <!--GUICE DEPENDENCIES -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-servlet</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-persist</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <!-- HIBERNATE DEPENDENCIES -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-core.version}</version>
        </dependency>
        <!-- MYSQL DEPENDENCIES -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-connector-java.version}</version>
        </dependency>
        <!-- WICKET DEPENDENCIES -->
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-core</artifactId>
            <version>${wicket.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-guice</artifactId>
            <version>${wicket.version}</version>
        </dependency>

        <!-- LOGGING DEPENDENCIES - LOG4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>Apache Nexus</id>
            <url>https://repository.apache.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

I want to find out how to use Guice Persist (Guice 3.0) with Wicket 1.5.

I have not been able to find any 'hello world' type examples explaining how to do this, if you can link/provide such an example that would be great, and happily accepted as an answer.

In the meantime I'll be trying to create a 'hello world' type example myself, posting the code here as I progress. Help with making my code function properly will also be accepted as an answer.


I have set up a simple wicket project, very similar to the 'hello world' guice example from Wicket Examples, that uses guice for dependency injection. I now want to extend this project to also use JPA and Guice Persist, instead of "Hello World" I want to fetch a User from the database and display its username. I'm trying to achieve this using the instructions from the Guice wiki about Guice persist.

UPDATE: So, I kinda got it working. In WebApplication.init() I injected a ServetModule like this getComponentInstantiationListeners().add(new GuiceComponentInjector(this, new MyServletModule())); and I also added GuiceFilter at the top of the web.xml file, before wickets filter.

Now when I run the application everything works, but I get this warning about using deprecated methods. Will look into this further.

WARNING: You are attempting to use a deprecated API (specifically,
attempting to @Inject ServletContext inside an eagerly created
singleton. While we allow this for backwards compatibility, be warned
that this MAY have unexpected behavior if you have more than one
injector (with ServletModule) running in the same JVM. Please consult
the Guice documentation at
http://code.google.com/p/google-guice/wiki/Servlets for more
information.

Directory tree

.
├── pom.xml
└── src
    └── main
        ├── java
        │   └── se
        │       └── lil
        │           ├── HomePage.html
        │           ├── HomePage.java
        │           ├── MyServletModule.java
        │           ├── WicketApplication.java
        │           ├── domain
        │           │   └── User.java
        │           └── service
        │               ├── IService.java
        │               └── JpaService.java
        ├── resources
        │   ├── META-INF
        │   │   └── persistence.xml
        │   └── log4j.properties
        └── webapp
            └── WEB-INF
                └── web.xml

WicketApplication.java

public class WicketApplication extends WebApplication {
    @Override
    protected void init() {
        super.init();
        getComponentInstantiationListeners().add(new GuiceComponentInjector(this,
                new MyServletModule()));
    }

    @Override
    public Class<? extends Page> getHomePage() {
        return se.lil.HomePage.class;
    }
}

HomePage.java

public class HomePage extends WebPage {
    private static final long serialVersionUID = -918138816287955837L;

    @Inject
    private IService service;

    private IModel<User> model = new LoadableDetachableModel<User>() {
        private static final long serialVersionUID = 1913317225318224531L;

        @Override
        protected User load() {
            return service.getUser();
        }
    };

    public HomePage() {
        setDefaultModel(new CompoundPropertyModel<User>(model));
        add(new Label("name"));
    }
}

HomePage.html

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:wicket="http://wicket.apache.org">
<head>
<title>Wicket Examples - guice</title>
</head>
<body>
    <hr />
        Value: <b wicket:id="name">name goes here</b> <br />
    <hr />
</body>
</html>

MyServletModule.java

public class MyServletModule extends ServletModule {
    protected void configureServlets() {
        install(new JpaPersistModule("manager1"));
        filter("/*").through(PersistFilter.class);
    }
}

IService.java

@ImplementedBy(JpaService.class)
public interface IService {
    public User getUser();
}

JpaService.java

public class JpaService implements IService {
    @Inject
    private EntityManager em;

    @Override
    @Transactional
    public User getUser() {
        Query q = em.createQuery("FROM User");
        q.setMaxResults(1);
        User u = (User) q.getSingleResult();
        return u;
    }
}

User.java

@Entity
@Table (name = "users")
public class User {
    private Long id;
    private String name;

    public User() {
    }

    public User(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }
    @SuppressWarnings("unused")
    private void setId(Long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }   
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <display-name>wicketwithguice</display-name>

    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>wicket.wicketwithguice</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>se.lil.WicketApplication</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>wicket.wicketwithguice</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>se.lil.domain.User</class> 
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
            <property name="hibernate.show_sql" value="true"/>

            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/test"/>
            <property name="javax.persistence.jdbc.user" value="test"/>
            <property name="javax.persistence.jdbc.password" value="1234"/>
        </properties>
    </persistence-unit>
</persistence>

pom.xml

<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>se.lil</groupId>
    <artifactId>wicketwithquice</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <!-- TODO project name -->
    <name>quickstart</name>
    <description></description>
    <!-- TODO <organization> <name>company name</name> <url>company url</url> </organization> -->

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <hibernate-core.version>3.6.4.Final</hibernate-core.version>
        <mysql-connector-java.version>5.1.16</mysql-connector-java.version>
        <slf4j.version>1.6.1</slf4j.version>
        <log4j.version>1.6.1</log4j.version>
        <guice.version>3.0</guice.version>
        <wicket.version>1.5.2</wicket.version>
    </properties>

    <dependencies>
        <!--GUICE DEPENDENCIES -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-servlet</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-persist</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <!-- HIBERNATE DEPENDENCIES -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-core.version}</version>
        </dependency>
        <!-- MYSQL DEPENDENCIES -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-connector-java.version}</version>
        </dependency>
        <!-- WICKET DEPENDENCIES -->
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-core</artifactId>
            <version>${wicket.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-guice</artifactId>
            <version>${wicket.version}</version>
        </dependency>

        <!-- LOGGING DEPENDENCIES - LOG4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>Apache Nexus</id>
            <url>https://repository.apache.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

静谧幽蓝 2024-12-19 03:34:39

Wicket 1.5.3 和 Guice 3 可以工作。对于 wicket wicket-ioc,除了 wicket core 和 wicket-guice 之外,还使用了 wicket-util 和 wicket-dev-utils。在 Netbeans7.0 中下载并创建了 jar,并将其添加到 Web 项目中。

Wicket 1.5.3 and Guice 3 work. For wicket wicket-ioc, wicket-util and wicket-dev-utils were used besides wicket core and wicket-guice.Jars were downloaded and created as a library in Netbeans7.0 and added to the web project.

只涨不跌 2024-12-19 03:34:39

由于当 guice 与 shiro 集成时会出现相同的消息,因此以下邮件列表可能有用
“http://mail-archives.apache.org/mod_mbox/shiro-user/201108.mbox/%[电子邮件受保护]%3E"

As the same message is learnt to be appearing when guice is integrated with shiro, the following mailing-list may be useful
"http://mail-archives.apache.org/mod_mbox/shiro-user/201108.mbox/%[email protected]%3E"

葵雨 2024-12-19 03:34:39

当从 ServletContext 获取 Injector 并将其添加到 GuiceComponentInjector 时,不会出现此类消息。此处提供的 AppListener 和其他代码的代码:

package cookbook;

import com.google.inject.persist.jpa.*;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.google.inject.persist.PersistFilter;
public class AppListener extends GuiceServletContextListener{
    @Override
    public Injector getInjector() {
    return Guice.createInjector(
      new  JpaPersistModule("WickGui3PU"  ),
      new ServletModule() {
        @Override
        protected void configureServlets() {



          filter("/*").through(PersistFilter.class);


          bind(BookDAO.class).to (BookDAOImpl.class);
        }
    });
    } 
}

添加到 web.xml

<listener>
      <listener-class>cookbook.AppListener</listener-class>
  </listener>

WicketApplication 中的 init() 应该如下所示:

 protected void init() {
        super.init();

                Injector injector = (Injector)getServletContext().getAttribute(Injector.class.getName());

        getComponentInstantiationListeners().add(new GuiceComponentInjector(this,injector));
    }

When Injector is obtained from ServletContext and added to GuiceComponentInjector no such message appears.The code for AppListener and others furnished here:

package cookbook;

import com.google.inject.persist.jpa.*;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.google.inject.persist.PersistFilter;
public class AppListener extends GuiceServletContextListener{
    @Override
    public Injector getInjector() {
    return Guice.createInjector(
      new  JpaPersistModule("WickGui3PU"  ),
      new ServletModule() {
        @Override
        protected void configureServlets() {



          filter("/*").through(PersistFilter.class);


          bind(BookDAO.class).to (BookDAOImpl.class);
        }
    });
    } 
}

Add in web.xml

<listener>
      <listener-class>cookbook.AppListener</listener-class>
  </listener>

The init() in WicketApplication should be as under:

 protected void init() {
        super.init();

                Injector injector = (Injector)getServletContext().getAttribute(Injector.class.getName());

        getComponentInstantiationListeners().add(new GuiceComponentInjector(this,injector));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文