简体   繁体   中英

how to access file in root server with spring security

i am using grails 3.1.1 i already deployment my war file with tomcat 8 and i store all my image's file into /app/Item/

this is my folder's structure in my server.

/app/Item/<all my image>
/home
/root/apache-tomcat-8/
     /apache-tomcat-8/webapps
     /apache-tomcat-8/webapps/ROOT.war
     /apache-tomcat-8/bin
     /apache-tomcat-8/logs
     /apache-tomcat-8/work
     /apache-tomcat-8/temp
     /apache-tomcat-8/conf

now i am using symlink to access /app/Item so i create a symlink in /apache-tomcat-8/webapps/images with name images so when i access localhost:8080/images/100.JPG it will access to /app/Item/100.JPG

but i will get some error log if i rerun my tomcat, because folder images where i create with symlink isnot in my grails project. like this..

28-Feb-2017 12:43:44.962 WARNING [localhost-startStop-2] org.apache.naming.NamingContext.lookup Unexpected exception resolving reference
 java.sql.SQLException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader
  context: gambarku
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1fb3ebeb

    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:283)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:718)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:650)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)

now i want to know how to access my folder /app/Item/ without symlink but from my grails application?

i tried to deploy without symlink or images 's folder (shortcut)

    [root@li1447-147 bin]# cd ..
[root@li1447-147 apache-tomcat-8.5.8]# cd we
-bash: cd: we: No such file or directory
[root@li1447-147 apache-tomcat-8.5.8]# cd webapps/
[root@li1447-147 webapps]# rm -rf *
[root@li1447-147 webapps]# clear
[root@li1447-147 webapps]# cd ..
[root@li1447-147 apache-tomcat-8.5.8]# cd bin/
[root@li1447-147 bin]# ./startup.sh
Using CATALINA_BASE:   /root/apache-tomcat-8.5.8
Using CATALINA_HOME:   /root/apache-tomcat-8.5.8
Using CATALINA_TMPDIR: /root/apache-tomcat-8.5.8/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_112
Using CLASSPATH:       /root/apache-tomcat-8.5.8/bin/bootstrap.jar:/root/apache-    tomcat-8.5.8/bin/tomcat-juli.jar
Tomcat started.
[root@li1447-147 bin]# tail -f ../logs/catalina.out
28-Feb-2017 16:13:06.353 INFO [main] org.apache.coyote.AbstractProtocol.init Ini    tializing ProtocolHandler ["http-nio-80"]
28-Feb-2017 16:13:06.368 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.    getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.370 INFO [main] org.apache.coyote.AbstractProtocol.init Ini    tializing ProtocolHandler ["https-jsse-nio-443"]
28-Feb-2017 16:13:06.613 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.    getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.613 INFO [main] org.apache.coyote.AbstractProtocol.init Ini    tializing ProtocolHandler ["ajp-nio-8009"]
28-Feb-2017 16:13:06.615 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.    getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.615 INFO [main] org.apache.catalina.startup.Catalina.load I    nitialization processed in 796 ms
28-Feb-2017 16:13:06.637 INFO [main] org.apache.catalina.core.StandardService.st    artInternal Starting service Catalina
28-Feb-2017 16:13:06.637 INFO [main] org.apache.catalina.core.StandardEngine.sta    rtInternal Starting Servlet Engine: Apache Tomcat/8.5.8
28-Feb-2017 16:13:06.657 INFO [localhost-startStop-1] org.apache.catalina.startu    p.HostConfig.deployWAR Deploying web application archive /root/apache-tomcat-8.5    .8/webapps/ROOT.war
28-Feb-2017 16:13:13.193 INFO [localhost-startStop-1] org.apache.jasper.servlet.    TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs.     Enable debug logging for this logger for a complete list of JARs that were scan    ned but no TLDs were found in them. Skipping unneeded JARs during scanning can i    mprove startup time and JSP compilation time.

Configuring Spring Security Core ...
... finished configuring Spring Security Core

28-Feb-2017 16:13:49.628 INFO [localhost-startStop-1] org.apache.catalina.startu    p.HostConfig.deployWAR Deployment of web application archive /root/apache-tomcat    -8.5.8/webapps/ROOT.war has finished in 42,968 ms
28-Feb-2017 16:13:49.632 INFO [main] org.apache.coyote.AbstractProtocol.start St    arting ProtocolHandler [http-nio-80]
28-Feb-2017 16:13:49.638 INFO [main] org.apache.coyote.AbstractProtocol.start St    arting ProtocolHandler [https-jsse-nio-443]
28-Feb-2017 16:13:49.639 INFO [main] org.apache.coyote.AbstractProtocol.start St    arting ProtocolHandler [ajp-nio-8009]
28-Feb-2017 16:13:49.640 INFO [main] org.apache.catalina.startup.Catalina.start     Server startup in 43024 ms

------------------this is for symlink

then i tried to read this and add this code to my server.xml

<Context docBase="/app/Item" path="/gambarku" />

then startup.sh again.

i get this log.

28-Feb-2017 17:00:49.701 WARNING [localhost-startStop-1] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader
  context: gambarku
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1fb3ebeb

28-Feb-2017 17:00:49.772 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /root/apache-tomcat-8.5.8/webapps/ROOT.war
28-Feb-2017 17:00:56.238 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

this log is same when i tried to use symlink .

i tried to find some documentation and i already check in folder WEB-INF/lib/mysql-connector-java-5.1.20.jar and build.gradle with runtime 'mysql:mysql-connector-java:5.1.20'

在此处输入图片说明

在此处输入图片说明

def image = new File('/app/Item/image1.jpg')

This is a long shot but might solve your issue, it's very similar to the config you had originally, just adding allowLinking="true" :

  • Create a symlink between /app/Item and /apache-tomcat-8/webapps/images
  • Add this to your configuration

      <Context docBase="/app/Item" path="/images" allowLinking="true"/> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM