문제

I have a web-app that requires two settings:

  • A JDBC datasource
  • A string token

I desperately want to be able to deploy one .war to various different containers (jetty,tomcat,gf3 minimum) and configure these settings at application level within the container.

My code does this:

InitialContext ctx = new InitialContext();
Context envCtx = (javax.naming.Context) ctx.lookup("java:comp/env");
token = (String)envCtx.lookup("token");
ds = (DataSource)envCtx.lookup("jdbc/datasource")

Let's assume I've used the glassfish management interface to create two jdbc resources: jdbc/test-datasource and jdbc/live-datasource which connect to different copies of the same schema, on different servers, different credentials etc. Say I want to deploy this to glassfish with and point it at the test datasource, I might have this in my sun-web.xml:

...
<resource-ref>
  <res-ref-name>jdbc/datasource</res-ref-name>
  <jndi-name>jdbc/test-datasource</jndi-name>
</resource-ref>
...

but

  • sun-web.xml goes inside my war, right?
  • surely there must be a way to do this through the management interface

Am I even trying to do the right thing? Do other containers make this any easier? I'd be particularly interested in how jetty 7 handles this since I use it for development.

EDIT Tomcat has a reasonable way to do this:

Create $TOMCAT_HOME/conf/Catalina/localhost/webapp.xml with:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true">
  <!-- String resource -->
  <Environment name="token" value="value of token" type="java.lang.String" override="false" />

  <!-- Linking to a global resource -->
  <ResourceLink name="jdbc/datasource1" global="jdbc/test" type="javax.sql.DataSource" />

  <!-- Derby -->
  <Resource name="jdbc/datasource2"
    type="javax.sql.DataSource"
    auth="Container"
    driverClassName="org.apache.derby.jdbc.EmbeddedDataSource"
    url="jdbc:derby:test;create=true"
    />

  <!-- H2 -->
  <Resource name="jdbc/datasource3"
    type="javax.sql.DataSource"
    auth="Container"
    driverClassName="org.h2.jdbcx.JdbcDataSource"
    url="jdbc:h2:~/test"
    username="sa"
    password=""
    />
</Context>

Note that override="false" means the opposite. It means that this setting can't be overriden by web.xml.

I like this approach because the file is part of the container configuration not the war, but it's not part of the global configuration; it's webapp specific.

I guess I expect a bit more from glassfish since it is supposed to have a full web admin interface, but I would be happy enough with something equivalent to the above.

올바른 솔루션이 없습니다

다른 팁

For GF v3, you may want to try leveraging the --deploymentplan option of the deploy subcommand of asadmin. It is discussed on the man page for the deploy subcommand.

나는 동일한 문제에 대해서도 만났으며, 여기에서 내가 어떻게 해결하는지

증상

  • style= 'display : 없음' " 를 삭제했습니다.
  • true "에 ASP 컨트롤의" 가시적 인 "속성을 설정했습니다.
  • 드롭 다운이 표시되어 있음에도 불구하고 아이콘이 비어있었습니다.

    해상도

    1. IE에서 F12 개발자 도구를 열고 HTML "MS-BreadCrumb-dropdownbox" 클래스에서 찾습니다.
    2. HTML DOM을 DIV에 따라 " 의 하이퍼 링크를 찾을 수 있습니다. .
    3. 이 링크 내에서 태그를 찾은 다음 " src "속성에서 URL을 확인하고 웹 브라우저에 직접이 이미지를로드하려고 시도합니다.
    4. 태그가 존재하지 않는 것에 지정된 파일 (즉, 404를 리턴 할 것)에 명시된 파일이다. 이는 마스터 페이지가 시작하는 사용자 정의 테마 또는 기타 기괴한 SharePoint 문제가 있기 때문일 수 있습니다.
    5. SharePoint Designer를 열고 해당 이미지를 탐색하고 해당 이미지 파일을 찾으십시오. "/_layouts/15/images/spcommon.png?rev=에있는 기본 요소를 복사하십시오. 23 "그리고 거기에있을 것으로 예상 한 사람에게 이름을 바꿉니다.
    6. 인터넷 브라우저에서 캐시를 새로 고침 하고이 시간에 이미지가 올바르게로드되어야합니다.

      평소와 같이 모든 사람을위한 해결이 아닐 수도 있지만 다른 사람들에게 도움이 될 수 있기를 바랍니다.)

I'm not sure to really understand the question/problem.

As an Application Component Provider, you declare the resource(s) required by your application in a standard way (container agnostic) in the web.xml.

At deployment time, the Application Deployer and Administrator is supposed to follow the instructions provided by the Application Component Provider to resolve external dependencies (amongst other things) for example by creating a datasource at the application server level and mapping its real JNDI name to the resource name used by the application through the use of an application server specific deployment descriptor (e.g. the sun-web.xml for GlassFish). Obviously, this is a container specific step and thus not covered by the Java EE specification.

Now, if you want to change the database an application is using, you'll have to either:

  • change the mapping in the application server deployment descriptor - or -
  • modify the configuration of the existing datasource to make it points on another database.

Having an admin interface doesn't really change anything. If I missed something, don't hesitate to let me know. And just in case, maybe have a look at this previous answer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top